Best Practices for Scientific Computing

This post originally appeared on the Software Carpentry website.

The following pre-print is now available on arXiv:

D.A. Aruliaha, C. Titus Brownb, Neil P. Chue Hongc, Matt Davisd, Richard T. Guye, Steven H.D. Haddockf, Katy Huffg, Ian Mitchellh, Mark Plumbleyi, Ben Waughj, Ethan P. Whitek, Greg Wilsonl, and Paul Wilsong.

aUniversity of Ontario Institute of Technology, bMichigan State University, cSoftware Sustainability Institute, dSpace Telescope Science Institute, eUniversity of Toronto, fMonterey Bay Aquarium Research Institute, gUniversity of Wisconsin, hUniversity of British Columbia, iQueen Mary University London, jUniversity College London, kUtah State University, and lSoftware Carpentry.


Scientists spend an increasing amount of time building and using software. However, most scientists are never taught how to do this efficiently. As a result, many are unaware of tools and practices that would allow them to write more reliable and maintainable code with less effort. We describe a set of best practices for scientific software development that have solid foundations in research and experience, and that improve scientists' productivity and the reliability of their software.

  1. Write programs for people, not computers.
    1. A program should not require its readers to hold more than a handful of facts in memory at once.
    2. Names should be consistent, distinctive, and meaningful.
    3. Code style and formatting should be consistent.
    4. All aspects of software development should be broken down into tasks roughly an hour long.
  2. Automate repetitive tasks.
    1. Rely on the computer to repeat tasks.
    2. Save recent commands in a file for re-use.
    3. Use a build tool to automate their scientific workflows.
  3. Use the computer to record history.
    1. Software tools should be used to track computational work automatically.
  4. Make incremental changes.
    1. Work in small steps with frequent feedback and course correction.
  5. Use version control.
    1. Use a version control system.
    2. Everything that has been created manually should be put in version control.
  6. Don't repeat yourself (or others).
    1. Every piece of data must have a single authoritative representation in the system.
    2. Code should be modularized rather than copied and pasted.
    3. Re-use code instead of rewriting it.
  7. Plan for mistakes.
    1. Add assertions to programs to check their operation.
    2. Use an off-the-shelf unit testing library.
    3. Turn bugs into test cases.
    4. Use a symbolic debugger.
  8. Optimize software only after it works correctly.
    1. Use a profiler to identify bottlenecks}.
    2. Write code in the highest-level language possible.
  9. Document the design and purpose of code rather than its mechanics.
    1. Document interfaces and reasons, not implementations.
    2. Refactor code instead of explaining how it works.
    3. Embed the documentation for a piece of software in that software.
  10. Conduct code reviews.
    1. Use code review and pair programming when bringing someone new up to speed and when tackling particularly tricky design, coding, and debugging problems.
    2. Use an issue tracking tool.

Dialogue & Discussion

Comments must follow our Code of Conduct.

Edit this page on Github