Next: C++ Sources, Previous: General Guidelines, Up: Contributing Guidelines [Contents][Index]
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 indexing expressions, 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))
When constructing matrices, prefer using the comma rather than the space to distinguish between columns.
M = [1, 2, 3 4, 5, 6];
However, if the matrix is large or the indentation makes it clear the comma may be dropped.
prices = [ 1.01 2.02 3.03 44.04 55.05 6.06];
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 condition of an if
, while
, until
, or
switch
statement 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
The Octave operator ‘!’ should be used for logical negation, rather than
‘~’. The negation operator is written with a space between the operator
and its target, e.g., ! A
.
Comments should begin with the ‘#’ character, rather than ‘%’. See Comment Tips.
Any demos or Built-In Self Tests (BIST) using the %!demo
or
%!test
syntax should begin two lines after the endfunction
keyword. Demo blocks should be listed before test blocks.
Next: C++ Sources, Previous: General Guidelines, Up: Contributing Guidelines [Contents][Index]