1@c Copyright (C) 2008 Jaroslav Hajek <highegg@gmail.com>
3@c This file is part of Octave.
5@c Octave is free software; you can redistribute it and/or modify it
6@c under the terms of the GNU General Public License as published by the
7@c Free Software Foundation; either version 3 of the License, or (at
8@c your option) any later version.
10@c Octave is distributed in the hope that it will be useful, but WITHOUT
11@c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12@c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15@c You should have received a copy of the GNU General Public License
16@c along with Octave; see the file COPYING. If not, see
17@c <http://www.gnu.org/licenses/>.
19@node Contributing Guidelines
20@appendix Contributing Guidelines
21@cindex coding standards
22@cindex Octave development
24This chapter is dedicated to those who wish to contribute code to Octave.
27* How to Contribute:: How you may start contributing code.
28* General Guidelines:: Advices applicable to any type of source.
29* Octave Sources (m-files)::
34@node How to Contribute
35@section How to Contribute
36The mailing list for Octave development discussion and sending contributions is
37@email{maintainers@@octave.org}. This concerns the development of Octave core,
38i.e. code that goes to Octave directly. You may consider developing and
39publishing a package instead; a great place for this is the allied Octave-Forge
40project (@url{http://octave.sf.net}). Note that the Octave project is
41inherently more conservative and follows narrower rules.
43The preferable form of contribution is creating a Mercurial changeset and
44sending it via e-mail to the octave-maintainers mailing list. Mercurial is the
45SCM system currently used to develop Octave. Other forms of contributions (e.g.
46simple diff patches) are also acceptable, but they slow down the review process.
47If you want to make more contributions, you should really get familiar with
48Mercurial. A good place to start is
49@url{http://www.selenic.com/mercurial/wiki/index.cgi/Tutorial}.
50A simplified contribution sequence could look like this:
53hg clone http://www.octave.org/hg/octave
55# change some sources...
56hg commit -m "make Octave the coolest software ever"
58# send ../cool.diff via email
61@node General Guidelines
62@section General Guidelines
64All Octave's sources are distributed under the General Public License (GPL).
65Currently, Octave uses GPL version 3. For details about this license, see
66@url{http://www.gnu.org/licenses/gpl.html}. Therefore, whenever you create a
67new source file, it should have the following comment header (use appropriate
68year, name and comment marks):
71## Copyright (C) 1996, 1997, 2007 John W. Eaton <jwe@@bevo.che.wisc.edu>
73## This file is part of Octave.
75## Octave is free software; you can redistribute it and/or
76## modify it under the terms of the GNU General Public
77## License as published by the Free Software Foundation;
78## either version 3 of the License, or (at your option) any
81## Octave is distributed in the hope that it will be useful,
82## but WITHOUT ANY WARRANTY; without even the implied
83## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
84## PURPOSE. See the GNU General Public License for more
87## You should have received a copy of the GNU General Public
88## License along with Octave; see the file COPYING. If not,
89## see <http://www.gnu.org/licenses/>.
92Always include ChangeLog entries in changesets. After making your source
93changes, record and briefly describe the changes in the nearest ChangeLog file
94upwards in the directory tree. Use the previous entries as a template. Your
95entry should contain your name and email, and the path to the modified source
96file relative to the parent directory of the ChangeLog file. If there are more
97functions in the file, you should also include the name of the modified function
98(in parentheses after file path). Example:
1012008-04-02 David Bateman <dbateman@@free.fr>
103 * graphics.cc (void gnuplot_backend::close_figure (const
104 octave_value&) const): Allow for an input and output stream.
108The ChangeLog entries should describe what is changed, not why. The reason of
109the change should appear in the commit message.
111@node Octave Sources (m-files)
112@section Octave Sources (m-files)
114Don't use tabs. Tabs cause trouble. If you are used to them, set up your editor
115so that it converts tabs to spaces. Indent the bodies of the statement blocks.
116Recommended indent is 2 spaces. When calling functions, put spaces after commas
117and before the calling parentheses, like this:
120 x = max (sin (y+3), 2);
124An exception are matrix and vector constructors:
131Here, putting spaces after @code{sin}, @code{cos} would result in a parse error.
132In indexing expression, do not put a space after the identifier (this
133differentiates indexing and function calls nicely). The space after comma is not
134necessary if index expressions are simple, i.e. you may write
143 A([1:i-1;i+1:n], XI(:,2:n-1))
146Use lowercase names if possible. Uppercase is acceptable for variable names
147consisting of 1-2 letters. Do not use mixed case names. Function names must be
148lowercase. Function names are global, so choose them wisely.
150Always use a specific end-of-block statement (like @code{endif},
151@code{endswitch}) rather than generic @code{end}. Enclose the @code{if},
152@code{while}, @code{until} and @code{switch} conditions in parentheses,
162Do not do this, however, with @code{for}:
173Don't use tabs. Tabs cause trouble. If you are used to them, set up your editor
174so that it converts tabs to spaces. Format function headers like this:
178matches_patterns (const string_vector& patterns, int pat_idx,
179 int num_pat, const std::string& name)
183The function name should start in column 1, and multi-line argument lists should
184be aligned on the first char after the open parenthesis. You should put a space
185after the left open parenthesis and after commas, for both function definitions
188Recommended indent is 2 spaces. When indenting, indent the statement after
189control structures (like @code{if}, @code{while} etc.). If there is a compound
190statement, indent @i{both} the curly braces and the body of the statement (so
191that the body gets indented by @i{two} indents). Example:
196 idx.push_back (first_args);
200 idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp));
204If you have nested @code{if} statements, use extra braces for extra
207Split long expressions in such a way that a continuation line starts with an
208operator rather than identifier. If the split occurs inside braces, continuation
209should be aligned with the first char after the innermost braces enclosing the
213SVD::type type = ((nargout == 0 || nargout == 1)
215 : (nargin == 2) ? SVD::economy : SVD::std);
219Consider putting extra braces around a multiline expression to make it more
220readable, even if they are not necessary. Also, do not hesitate to put extra
221braces anywhere if it improves clarity.
223Try declaring variables just before they're needed. Use local variables of
224blocks - it helps optimization. Don't write multi-line variable declaration
225with a single type specification and multiple variables. If the variables don't
226fit on single line, repeat the type specification. Example:
231octave_idx_type nr = b.rows ();
232octave_idx_type nc = b.cols ();
237Use lowercase names if possible. Uppercase is acceptable for variable names
238consisting of 1-2 letters. Do not use mixed case names.
240Try to use Octave's types and classes if possible. Otherwise, try to use C++
241standard library. Use of STL containers and algorithms is encouraged. Use
242templates wisely to reduce code duplication. Avoid comma expressions, labels
243and gotos, and explicit typecasts. If you need to typecast, use the modern C++
244casting operators. In functions, try to reduce the number of @code{return}
245statements - use nested @code{if} statements if possible.
248@section Other Sources
249Apart from C++ and Octave language (m-files), Octave's sources include files
250written in C, Fortran, M4, perl, unix shell, AWK, texinfo and TeX. There are
251not many rules to follow when using these other languages; some of them are
252summarized below. In any case, the golden rule is: if you modify a source
253file, try to follow any conventions you can detect in the file or other similar
256For C you should obviously follow all C++ rules that can apply.
258If you happen to modify a Fortran file, you should stay within Fortran 77
259with common extensions like @code{END DO}. Currently, we want all sources
260to be compilable with the f2c and g77 compilers, without special flags if
261possible. This usually means that non-legacy compilers also accept the sources.
263The M4 macro language is mainly used for autoconf configuration files. You should
264follow normal M4 rules when contributing to these files. Some M4 files come
265from external source, namely the Autoconf archive @url{http://autoconf-archive.cryp.to}.