Matlab Coding guidelines


On writing readable matlab code

[In development]

Rule 1: The code you run and re-run on different stuff should be functions

  • Functions can be shared / read used by others.  Scripts generally cannot.  Script with front-matter inputs = bad (or temporary code to become function).
  • Any code chunk that has a general format / is likely to be reused should become its own function.
  • If code is comprised of functions that have clearly defined input output behavior, it’s less critical the that underlying code is readable, as long as its fast/efficient.
  • this is not an excuse to write non-readable functions, but a practice that will make the code more readable (i.e. recognize a call to plotdata(). rather than all the detailed lines that setup the plot.
Rule 2: Scripts should be run once, and saved as version managed marked up outputs.  
  • ‘Publish’ the script instead of running it.  This will save a copy of the script and all the output to screen and figures. 
  • use Git to version manage the html files output.  Auto-commit upon publication? (save changes to script?)  

Frontmatter for functions

  • inputs
  • outputs

choose conventions for filenames / function names / etc (?)

  • CamelNotation
  • underscore_notation
  • matlabnamestyle
This entry was posted in Research Planning and tagged . Bookmark the permalink.