Next: C++ Sources, Previous: General Guidelines, Up: Contributing Guidelines [Contents][Index]

### D.5 Octave Sources (m-files)

Don’t use tabs. Tabs cause trouble. If you are used to them, set up your editor so that it converts tabs to spaces. Indent the bodies of statement blocks. The recommended indent is 2 spaces. When calling functions, put spaces after commas and before the calling parentheses, like this:

      x = max (sin (y+3), 2);

An exception are matrix or cell constructors:

      [sin(x), cos(x)]
      {sin(x), cos(x)}

Here, putting spaces after `sin`, `cos` would result in a parse error. For an indexing expression, do not put a space after the identifier (this differentiates indexing and function calls nicely). The space after a comma is not necessary if index expressions are simple, i.e., you may write

      A(:,i,j)

but

      A([1:i-1;i+1:n], XI(:,2:n-1))

Use lowercase names if possible. Uppercase is acceptable for variable names consisting of 1-2 letters. Do not use mixed case names. Function names must be lowercase. Function names are global, so choose them wisely.

Always use a specific end-of-block statement (like `endif`, `endswitch`) rather than the generic `end`.

Enclose the `if`, `while`, `until`, and `switch` conditions in parentheses, as in C:

    if (isvector (a))
      s = sum (a);
    endif

Do not do this, however, with the iteration counter portion of a `for` statement. Write:

    for i = 1:n
      b(i) = sum (a(:,i));
    endfor