Quality Assurance of Analytical Code playbook #253
Replies: 6 comments 2 replies
Working group - 15 Nov 2023Attendees
Agenda
Decisions and actions
|
Modular code and workflows
What is modular code?Complex analysis projects and workflows can often lead to a lot of code being written with some or a lot of that code performing repetitive tasks. Breaking down your code and workflow into smaller reusable chunks to can help you maintain your project and share components across a series of analyses. Tools such as R, Python, SQL, and Alteryx provide methods to create containerised code such as modules, classes, functions and macros. Why should I do this?Writing your code in a modular way provides a range of benefits:
How do we do it then?Writing modular code or developing modular workflows can differ depending on the your tool of choice, the needs of the project or piece of work, the intended customer, or the expected users of the code in the future. However, a simple hierarchy of actions to take are:
Let's dive into how we can do some of these. Split your code into multiple scriptsMonolithic code is a big no-no. A large and complex piece of code that runs into hundreds, if not thousands, of lines is unwieldy, difficult to read, debug and maintain, and pretty mean to pass off for peer review on a Friday afternoon. Splitting your monolithic code into ordered scripts can help others (and yourself) understand the steps you've taken and the reasons why.
For example, in R a large project could be split into: these scripts can now be run in their intended order and splits out the parts of your code into related areas, making peer review easier. Using scripts doesn't inherently make your code reproducible or reusable, but are a good first step towards better and higher quality code. Do
Don't
Use a code notebookServices such as Jupyter notebooks or R Markdown allow you write code, commentary and visualisations alongside each other. They can be incredibly useful, and individual workbooks can be a good first step towards modularising your code for simple projects and workflows and for doing initial data exploration. However, they can be difficult to use with further practices for producing high quality code. For example:
How will this be enforced? |
Working group - 13 Dec 2023Attendees
Agenda
Summary
Actions
TopicsMatthew - Modular code + configuration |
Readble codePre-requisite readingAF Duck book: Reable code What is reable code?Readable code is written with clarity and simplicity, making it easy for others to understand and maintain. It prioritises the reader's experience over the convenience of writing code. Why should we write reable code?
How do we write reable code?
By following these guidelines, we create a codebase that is easier to read, understand, and contribute to, ultimately leading to a more efficient and effective development process. For more detailed insights, please refer to the recommended pre-requisite reading. How will this be enforced? |
Peer Review
What is peer review?Peer review is a process where a second person will review a colleagues code before any code is finalised or used to produce output. Why should I do this?Although peer reviews can reduce potential bugs being missed, the peer review process is not simply a case of trying to catch errors. There are a number of benefits that to using a peer review approach, including:
How do we do it then?When using version control tools such as Git, peer review should be part of the branching and pull request process (see DDaT Playbook. Ideally a pull request should not be merged without the code being reviewed by somebody else. Using version control tools the basic steps for a peer review are (DRAFT NOTE: do we need more details or is this repeating DDaT playbook):
Do
Don't
It would be strongly recommended that version control tools are implemented and used for all pieces of work (DRAFT NOTE: link to playbook section on version control). However, where version control tools may not be in place, a peer review process would still be recommended, and notes should still be captured around any feedback and amendments raised during a review process. Pair programmingInstead of having the code writing and peer review as two distinct phases, pair programming combines these into a single step with two or more people actively working on the same piece of code at the same time. Effective pair programming will involve one person writing the code whilst the other(s) supply real time feedback on the code being written. The benefits of pair programming are that feedback can be provided as the code is being written, suggesting improvements or identifying/fixing issues as they appear. Additionally, pair programming can be a good method to share knowledge and experience between individuals. Pair programming may require more resource during the development stage but at the benefit in a reduce of resource needed for a review stage. For pair programming to be effective there are guidelines that should be followed:
How will peer review be enforced?
|
|
Picking up this old thread with a few questions/comments:
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This guidance is around the assurance of analytical code and low code workflows. These standards and guidance do not replace existing government, NHS, or BSA guidance but give the specifics of how we (should) write and assure code used in analysis across multiple languages and tools including R, Python, SQL, Alteryx, etc.
Workshops were carried out in May 2023 to understand current practices and documentation across Data teams.
This Discussion area will be used by the working group contributing to the guidance to draft ideas and as a collaborative space.
Topics
Possible additional topics:
Proposed timeline
Resources
Code assurance workshop summary
Code assurance SMT slides
All reactions