Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 379

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Octave Sources (m-files) - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Contributing-Guidelines.html#Contributing-Guidelines" title="Contributing Guidelines">
<link rel="prev" href="General-Guidelines.html#General-Guidelines" title="General Guidelines">
<link rel="next" href="C_002b_002b-Sources.html#C_002b_002b-Sources" title="C++ Sources">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Octave-Sources-(m-files)"></a>
<a name="Octave-Sources-_0028m_002dfiles_0029"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="C_002b_002b-Sources.html#C_002b_002b-Sources">C++ Sources</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="General-Guidelines.html#General-Guidelines">General Guidelines</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Contributing-Guidelines.html#Contributing-Guidelines">Contributing Guidelines</a>
<hr>
</div>

<h3 class="section">D.5 Octave Sources (m-files)</h3>

<p>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
the statement blocks.  Recommended indent is 2 spaces.  When calling
functions, put spaces after commas and before the calling parentheses,
like this:

<pre class="example">       x = max (sin (y+3), 2);
</pre>
   <p class="noindent">An exception are matrix and vector constructors:

<pre class="example">       [sin(x), cos(x)]
</pre>
   <p class="noindent">Here, putting spaces after <code>sin</code>, <code>cos</code> would result in a
parse error.  In indexing expression, do not put a space after the
identifier (this differentiates indexing and function calls nicely). 
The space after comma is not necessary if index expressions are simple,
i.e., you may write

<pre class="example">       A(:,i,j)
</pre>
   <p class="noindent">but

<pre class="example">       A([1:i-1;i+1:n], XI(:,2:n-1))
</pre>
   <p>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.

   <p>Always use a specific end-of-block statement (like <code>endif</code>,
<code>endswitch</code>) rather than generic <code>end</code>.

   <p>Enclose the <code>if</code>, <code>while</code>, <code>until</code> and <code>switch</code>
conditions in parentheses, like in C:

<pre class="example">     if (isvector (a))
       s = sum(a);
     endif
</pre>
   <p class="noindent">Do not do this, however, with the iteration counter portion of a
<code>for</code> statement.  Write:

<pre class="example">     for i = 1:n
       b(i) = sum (a(:,i));
     endfor
</pre>
   </body></html>