Octave style guide: Difference between revisions

→‎Whitespace: add style for arithmetic expressions
(→‎Quoted Strings: new section)
(→‎Whitespace: add style for arithmetic expressions)
Line 27: Line 27:
parentheses, like this:
parentheses, like this:


<pre>x = max (sin (y+3), 2);</pre>
<pre>x = max (sin (y + 3), 2);</pre>


An exception are matrix or cell constructors:
An exception are matrix or cell constructors:
Line 64: Line 64:
   prices = [ 1.01  2.02  3.03
   prices = [ 1.01  2.02  3.03
             44.04 55.05  6.06];
             44.04 55.05  6.06];
</pre>
Do include spaces around all binary arithmetic operators, for example
<pre>
  x = 1 / (1 + y) ^ 2;
</pre>
An exception is for extremely simple expressions like <pre>n+1</pre>, in
particular when used as an argument to a function or as part of an indexing
expression. For example, you may write
<pre>
  x(1:end-1)
</pre>
Another exception is for complex arithmetic expressions. It may improve
readability to omit spaces around higher precedence operators, for example
<pre>
  z = cat (dim, (x2.*y3 - x3.*y2), (x3.*y1 - x1.*y3), (x1.*y2 - x2.*y1));
</pre>
</pre>


296

edits