User Tools

Site Tools


en:software:matlab:trepr:dev:coding

Coding conventions

Everybody has his or her own ideas how to write proper code. For a somewhat consistent code basis of the toolbox, a few conventions for how to code functions for the toolbox are presented.

Please note: There is a list of general coding tips for, but not restricted to, Matlab™ programming.

The statement “real programmers never comment their code” is as old as stupid – and wrong. Write a function that consists of more than 50 lines of code and try to understand what you've done after you haven't looked at it for several months.

But comments are not the only thing that is important for proper coding, there are other things as well that make code easier to read. Actually, I know of code that is rarely documented, but nevertheless very much readable and easy to understand (Fortran77 code, by the way).

To get an idea what not to do, have a look at the classic: How To Write Unmaintainable Code - enjoy!

For the time being, just a list of bullet points:

  • Proper indentation of code
    (Use Matlab™'s code formatting capabilities)
  • Break long lines of code into several lines to increase readability.
  • Proper documentation header for every function
    Make use of the Matlab™ convention to display the first comment block of a function file if calling the function name together with help.
  • Straight below the documenting header, a two-liner with copyright and date of last change
  • Document throughout the code (concise and understandable).
  • Use informative variable names.
  • In “switch” constructs, add a “otherwise” clause whenever applicable.

And following here, a list of GUI-specific coding conventions:

en/software/matlab/trepr/dev/coding.txt · Last modified: 2020/09/30 21:35 by 127.0.0.1