Software Carpentry's aim is to make scientists better equipped to work with software just as if it was any other lab apparatus. Now we have its take on "Best Practices" and it is a lesson to us all scientist or not.
Software Carpentry teaches scientists to work with software in a more logical and organized way than is typical, In the old days lab equipment was mostly hardware and it was an important component of any experiment. It was put on show and scrutinized by other scientists. Not so with most of the software and even the data that is involved in most modern experiments. Scientists tend to take a casual approach to programming because it is so much easier than hardware. Of course well all know that it is only easier when you first start. As you slowly tangle yourself up in logical knots it gets harder and harder to work with. As a result lots of scientists tend to hide their code way and the same with raw data.
The point is that that the scenario just outlined not only applies to scientists but to just about anyone using or creating software in anything other than completely trivial ways.
In a recently published paper Software Carpentry outlines what it considers to be "best practice" and it is a document that has a relevance well beyond the strictly scientific.
It presents 24 specific things scientists, or programmers in general, can do to get more done in less time with less pain:
- Write programs for people, not computers.
- A program should not require its readers to hold more than a handful of facts in memory at once.
- Make names consistent, distinctive, and meaningful.
- Make code style and formatting consistent.
- Let the computer do the work.
- Make the computer repeat tasks.
- Save recent commands in a file for re-use.
- Use a build tool to automate workflows.
- Make incremental changes.
- Work in small steps with frequent feedback and course correction.
- Use a version control system.
- Put everything that has been created manually in version control.
- Don't repeat yourself (or others).
- Every piece of data must have a single authoritative representation in the system.
- Modularize code rather than copying and pasting.
- Re-use code instead of rewriting it.
- Plan for mistakes.
- Add assertions to programs to check their operation.
- Use an off-the-shelf unit testing library.
- Turn bugs into test cases.
- Use a symbolic debugger.
- Optimize software only after it works correctly.
- Use a profiler to identify bottlenecks.
- Write code in the highest-level language possible.
- Document design and purpose, not mechanics.
- Document interfaces and reasons, not implementations.
- Refactor code in preference to explaining how it works.
- Embed the documentation for a piece of software in that software.
- Use pre-merge code reviews.
- Use pair programming when bringing someone new up to speed and when tackling particularly tricky problems.
- Use an issue tracking tool.
For a more detailed explanation of each one see the paper which is free to download.