Course Information
1 Introduction
This course shows how to convert code into functions and modules. This gives code a better structure and as a result makes it reproducible and easier to maintain.
To do this we will go through a case study, where we re-structure existing code. During this we will highlight key concepts and considerations when designing code.
This course was created using existing guidance for programming for analysis in Government: Quality Assurance of Code for Analysis and Research, which contains extensive guidance on how to perform reproducible analysis.
2 Learning Objectives
The aim of this course is for participants to:
- understand why code should be structured, and how modules help with this
- be aware of different styles of programming
- understand the important considerations when converting code into functions
- be able to consider the necessary code changes when splitting code up across files
- be able to write code as functions and to import them
- consider how to group sets of functions into modules
3 Target Audience
This course contains explanations and examples in Python and R.
This course assumes basic programming knowledge. Having completed an introductory course or having experience in analysis would count.
This course shows how to structure code for analysis projects. It assumes the participant can already:
- work with data frames (load and manipulate)
- perform basic data analysis (summary statistics)
- write simple functions to perform tasks
4 Why Structure Code?
Well structured code is easier to read and easier to maintain.
Putting time into designing code well will payoff in the long run. Well structured code is important for reproducibility and effectiveness.
Writing programs quickly - without considering their design and structure - can cause significant headache and errors down the line.
You may come across Python and R files which do crucial work but are thousands of lines long without a clear order. These types of files and notebooks become difficult to understand as they get bigger. The less time spent scrolling through files looking for variables the better.
5 Where next?
Please choose either Getting Started in Python or Getting Started in R to begin your journey towards cleaner and more organised programming.
It’s recommended that you download all the datasets needed and store them in a data folder.