An introduction to collaborative coding and software engineering good practice
We are passionate about writing research software well. Please talk to us about software, we like to help (office 439).
https://neuroinformatics-unit.github.io/software-good-practice-course/
open / choose a task
write a solution to the task independent of main code
open a solution proposal
review a solution proposal
matplotlib.colors.get_named_colors_mapping()
def get_named_colors_mapping():
"""Return the global mapping of names to named colors."""
return _colors_full_map
Docstrings (should) follow an agreed convention
“Second, a 15-year-old bug was found … (the bug was fixed … during preparation of this manuscript). The bug essentially reduced the size of the image searched for clusters, underestimating the severity of the multiplicity correction and overestimating significance .” 1
“An in-house data reduction program introduced a change in sign for anomalous differences.
This program, which was not part of a conventional data processing package, converted the anomalous pairs (I+ and I−) to (F− and F+), thereby introducing a sign change.
We very sincerely regret the confusion that these papers have caused and, in particular, subsequent research efforts that were unproductive as a result of our original findings.” 1
“…basically, I forgot to set something to zero after I finished looping through the loop that moved the motor [and that caused a fire in the lab]”1
calculate_fastest_time
function?calculate_fastest_time
function?Switch to VS Code
A neater way to run sanity checks
What we’ve called sanity checks are referred to as “test cases”. Try to cover all “edge” cases1: what happens if …?
What we’ve called sanity checks are referred to as “test cases”. For example, what happens/should happen when you call…?
calculate_fastest_time("this is a string")
calculate_fastest_time([])
calculate_fastest_time([1.0]); calculate_fastest_time([2.0])
calculate_fastest_time([1.0, 0.5, 2.0])
calculate_fastest_time([1.0, 0.5, 2.0, sys.float_info.max]) # other extreme cases?
calculate_fastest_time([1.0, 0.5, 2.0, float("inf")])
Testing at different levels
Types of test:
No matter how much you test, things can still go wrong! (and it’s OK to make mistakes!)
“Program testing can be used to show the presence of bugs, but never to show their absence!” ― Edsger W. Dijkstra
A code smell is a surface indication that usually corresponds to a deeper problem in the system.
def calculate_fastest_time(time_list):
fastest_time = time_list[0]
for time in time_list:
if time > fastest_time:
fastest_time = time
return fastest_time
def print_fastest_time(time_list):
fastest_time = time_list[0]
for time in time_list:
if time > fastest_time:
fastest_time = time
print(f"This is the fastest time: {fastest_time} 🚀")
└── my-awesome-package/
├── LICENSE
├── MANIFEST.in
├── README.md
├── pyproject.toml
├── tox.ini
├── docs/
├── my_awesome_package/
│ └── __init__.py
│ └── do_something_awesome.py
└── tests/
├── __init__.py
└── test_placeholder.py
└── my-awesome-package/
├── LICENSE
├── MANIFEST.in
├── README.md
├── pyproject.toml
├── tox.ini
├── docs/
├── my_awesome_package/
│ └── __init__.py
│ └── do_something_awesome.py
└── tests/
├── __init__.py
└── test_placeholder.py
#software-skills
Collaborative coding and software engineering good practice | 2023-10-23