changelog shortlog tags changeset files revisions annotate raw

doc/interpreter/contrib.txi

changeset 8149: a8fb37ae61b8
child:65c4ac814082
author: John W. Eaton <jwe@octave.org>
date: Thu Sep 25 13:44:51 2008 -0400 (14 months ago)
permissions: -rw-r--r--
description: ChangeLog fixes
1@c Copyright (C) 2008 Jaroslav Hajek <highegg@gmail.com>
2@c
3@c This file is part of Octave.
4@c
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.
9@c
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
13@c for more details.
14@c
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/>.
18
19@node Contributing Guidelines
20@appendix Contributing Guidelines
21@cindex coding standards
22@cindex Octave development
23
24This chapter is dedicated to those who wish to contribute code to Octave.
25
26@menu
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)::
30* C++ Sources::
31* Other Sources::
32@end menu
33
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.
42
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:
51
52@example
53hg clone http://www.octave.org/hg/octave
54cd octave
55# change some sources...
56hg commit -m "make Octave the coolest software ever"
57hg export ../cool.diff
58# send ../cool.diff via email
59@end example
60
61@node General Guidelines
62@section General Guidelines
63
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):
69
70@example
71## Copyright (C) 1996, 1997, 2007 John W. Eaton <jwe@@bevo.che.wisc.edu>
72##
73## This file is part of Octave.
74##
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
79## later version.
80##
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
85## details.
86##
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/>.
90@end example
91
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:
99
100@example
1012008-04-02 David Bateman <dbateman@@free.fr>
102
103 * graphics.cc (void gnuplot_backend::close_figure (const
104 octave_value&) const): Allow for an input and output stream.
105@end example
106
107@noindent
108The ChangeLog entries should describe what is changed, not why. The reason of
109the change should appear in the commit message.
110
111@node Octave Sources (m-files)
112@section Octave Sources (m-files)
113
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:
118
119@example
120 x = max (sin (y+3), 2);
121@end example
122
123@noindent
124An exception are matrix and vector constructors:
125
126@example
127 [sin(x), cos(x)]
128@end example
129
130@noindent
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
135@example
136 A(:,i,j)
137@end example
138
139@noindent
140but
141
142@example
143 A([1:i-1;i+1:n], XI(:,2:n-1))
144@end example
145
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.
149
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,
153like in C:
154
155@example
156if (isvector (a))
157 s = sum(a);
158endif
159@end example
160
161@noindent
162Do not do this, however, with @code{for}:
163
164@example
165for i = 1:n
166 b(i) = sum (a(:,i));
167endfor
168@end example
169
170@node C++ Sources
171@section C++ Sources
172
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:
175
176@example
177static bool
178matches_patterns (const string_vector& patterns, int pat_idx,
179 int num_pat, const std::string& name)
180@end example
181
182@noindent
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
186and function calls.
187
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:
192
193@example
194if (have_args)
195 @{
196 idx.push_back (first_args);
197 have_args = false;
198 @}
199else
200 idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp));
201@end example
202
203@noindent
204If you have nested @code{if} statements, use extra braces for extra
205clarification.
206
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
210split. Example:
211
212@example
213SVD::type type = ((nargout == 0 || nargout == 1)
214 ? SVD::sigma_only
215 : (nargin == 2) ? SVD::economy : SVD::std);
216@end example
217
218@noindent
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.
222
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:
227
228@example
229octave_value retval;
230
231octave_idx_type nr = b.rows ();
232octave_idx_type nc = b.cols ();
233
234double d1, d2;
235@end example
236
237Use lowercase names if possible. Uppercase is acceptable for variable names
238consisting of 1-2 letters. Do not use mixed case names.
239
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.
246
247@node Other Sources
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
254files.
255
256For C you should obviously follow all C++ rules that can apply.
257
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.
262
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}.
266