Octave style guide

From Octave
Revision as of 09:12, 26 March 2016 by Carandraug (talk | contribs) (Start page describing our style guide for Octave code.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

Formatting

Line Length

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.

Indentation

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.

Naming

General naming functions

Function names

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. For example, base64_decode, common_size, or compare_versions. There are exceptions to this:

Matching C functions
If the function exists elsewhere with a common name, use it. For example, dup2, waitpid, printf, argv, or getopt.
Matching similar functions
If there are similarly named functions, consider using same style. For example, fftconvn and histthresh, match the naming of fftconv2 and graythresh.

Variable names

Comments

# or %

Always use # to write comments.

Absolutely do not use %# or mix % and # 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.