Skip to main content

13.10) Programming Best Practices


  • Make variable names consistent, distinctive, simple, and meaningful
  • Make code style and formatting consistent
  • Work in small steps - make incremental changes before retesting especially in large codes
  • Approach large problems in terms of small manageable chunks of code
  • Draw a flow-chart to help you design your code
  • Comment your code thoroughly (but not overwhelmingly - be succinct with comments!)
  • Include comments at the start which describe what the code does and what it needs for inputs and what it outputs. Include notes on how you have modified the code since its initial inception
  • Use a version control system
  • Modularise code rather than copy and pasting. Re-use code instead of rewriting
  • Plan for mistakes - Add assertions to code to check operation (i.e. sanity checks, generate intermediate test arrays that can be checked)
  • Optimize software only after it works - Use the Matlab Profiler to identify bottlenecks