Octave style guide
A lot of GNU Octave is written in the Octave language itself. This document details the Octave style used by the GNU Octave project.
Being part of the GNU project, Octave inherits the GNU coding standards. However, those were written with C in mind and can't always apply to Octave code.
See also the GNU Octave C++ style guide.
Keep the length of source lines to 79 characters or less, for maximum readability in the widest range of environments. This is inherited from the GNU Coding Standards.
Use only spaces, and indent 2 spaces at a time.
We use spaces for indentation. Absolutely do not use tabs in your code. You should probably set your editor to emit spaces when you hit the tab key.
General naming functions
For most public functions we are limited by Matlab compatibility. Use whatever name Matlab choose.
For functions that are not present in Matlab favour the use of underscores.
compare_versions. There are exceptions to this:
- Matching C functions
- If the function exists elsewhere with a common name, use it. For example,
- Matching similar functions
- If there are similarly named functions, consider using same style. For example,
histthresh, match the naming of
# or %
# to write comments.
Absolutely do not use
%# or mix
in the same file.
Block and Inline comment
Use a single
# for inline comments. Use double
for block comments.
Commenting out code
Do not comment code out. If the code is no longer used, remove it. We use version control, we can always bring it back.