rap-community-of-practice
rap-community-of-practice copied to clipboard
Clean code guidance
some teams want to use clean code - we need guidance on the best way to approach this for analytical code, why you would want to do it, and what to watch out for.
Some topics that could come up with regard to this (specifically with a python focus)
- Tidy data https://r4ds.had.co.nz/tidy-data.html
- How long should a function be? (Single responsibility principle)
- Variable naming
- Extracting magic numbers to a separate variable
# don't do this
if df_by_respondent["q23"] == 4:
pass
# do do this
ANSWERED_NOT_APPLICABLE = 4
if df_by_respondent["q23"] == ANSWERED_NOT_APPLICABLE:
pass
- The principles of self documenting code
- Type hints?
- Don't repeat yourself
- Using a
params.py
file - How long should a file be?
- Test driven development
This is in our backlog (https://nhsd-jira.digital.nhs.uk/browse/NV-1305)