Mercurial > hg > octave-lyh
comparison doc/interpreter/contrib.txi @ 11195:8f67fe9dd64e
contrib.txi: minor tweaks
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Nov 2010 09:08:47 -0400 |
parents | a4f482e66b65 |
children | fd0a3ac60b0e |
comparison
equal
deleted
inserted
replaced
11194:b8585f8e11d5 | 11195:8f67fe9dd64e |
---|---|
31 * Other Sources:: | 31 * Other Sources:: |
32 @end menu | 32 @end menu |
33 | 33 |
34 @node How to Contribute | 34 @node How to Contribute |
35 @section How to Contribute | 35 @section How to Contribute |
36 The mailing list for Octave development discussion and sending contributions is | 36 The mailing list for Octave development discussion and sending |
37 @email{maintainers@@octave.org}. This concerns the development of Octave core, | 37 contributions is @email{maintainers@@octave.org}. This concerns the |
38 i.e., code that goes to Octave directly. You may consider developing and | 38 development of Octave core, i.e., code that goes to Octave directly. |
39 publishing a package instead; a great place for this is the allied Octave-Forge | 39 You may consider developing and publishing a package instead; a great |
40 project (@url{http://octave.sf.net}). Note that the Octave project is | 40 place for this is the allied Octave-Forge project |
41 (@url{http://octave.sf.net}). Note that the Octave project is | |
41 inherently more conservative and follows narrower rules. | 42 inherently more conservative and follows narrower rules. |
42 | 43 |
43 The preferable form of contribution is creating a Mercurial changeset and | 44 The preferable form of contribution is creating a Mercurial changeset |
44 sending it via e-mail to the octave-maintainers mailing list. Mercurial is the | 45 and sending it via e-mail to the octave-maintainers mailing list. |
45 source code management system currently used to develop Octave. Other forms of | 46 Mercurial is the source code management system currently used to develop |
46 contributions (e.g., simple diff patches) are also acceptable, but they slow | 47 Octave. Other forms of contributions (e.g., simple diff patches) are |
47 down the review process. If you want to make more contributions, you should | 48 also acceptable, but they slow down the review process. If you want to |
48 really get familiar with Mercurial. A good place to start is | 49 make more contributions, you should really get familiar with Mercurial. |
49 @url{http://www.selenic.com/mercurial/wiki/index.cgi/Tutorial}. There you will | 50 A good place to start is |
50 also find help how to install Mercurial. | 51 @url{http://www.selenic.com/mercurial/wiki/index.cgi/Tutorial}. There |
52 you will also find help how to install Mercurial. | |
51 | 53 |
52 A simple contribution sequence could look like this: | 54 A simple contribution sequence could look like this: |
53 | 55 |
54 @example | 56 @example |
55 @group | 57 @group |
66 # file | 68 # file |
67 # send ../cool.diff via email | 69 # send ../cool.diff via email |
68 @end group | 70 @end group |
69 @end example | 71 @end example |
70 | 72 |
71 You may want to get familiar with Mercurial queues to manage your changesets. | 73 You may want to get familiar with Mercurial queues to manage your |
72 Here is a slightly less simple example using Mercurial queues, where you work | 74 changesets. Here is a slightly less simple example using Mercurial |
73 on two unrelated changesets in parallel and update one of the changesets after | 75 queues, where you work on two unrelated changesets in parallel and |
74 discussion in the maintainers mailing list: | 76 update one of the changesets after discussion in the maintainers mailing |
77 list: | |
75 | 78 |
76 @example | 79 @example |
77 hg qnew nasty_bug # create a new patch | 80 hg qnew nasty_bug # create a new patch |
78 # change sources@dots{} | 81 # change sources@dots{} |
79 hg qref # save the changes into the patch | 82 hg qref # save the changes into the patch |
103 @end example | 106 @end example |
104 | 107 |
105 @node General Guidelines | 108 @node General Guidelines |
106 @section General Guidelines | 109 @section General Guidelines |
107 | 110 |
108 All Octave's sources are distributed under the General Public License (GPL). | 111 All Octave's sources are distributed under the General Public License |
109 Currently, Octave uses GPL version 3. For details about this license, see | 112 (GPL). Currently, Octave uses GPL version 3. For details about this |
110 @url{http://www.gnu.org/licenses/gpl.html}. Therefore, whenever you create a | 113 license, see @url{http://www.gnu.org/licenses/gpl.html}. Therefore, |
111 new source file, it should have the following comment header (use appropriate | 114 whenever you create a new source file, it should have the following |
112 year, name and comment marks): | 115 comment header (use appropriate year, name and comment marks): |
113 | 116 |
114 @example | 117 @example |
115 ## Copyright (C) 1996, 1997, 2007 John W. Eaton <jwe@@octave.org> | 118 ## Copyright (C) 1996, 1997, 2007 John W. Eaton <jwe@@octave.org> |
116 ## | 119 ## |
117 ## This file is part of Octave. | 120 ## This file is part of Octave. |
131 ## You should have received a copy of the GNU General Public | 134 ## You should have received a copy of the GNU General Public |
132 ## License along with Octave; see the file COPYING. If not, | 135 ## License along with Octave; see the file COPYING. If not, |
133 ## see <http://www.gnu.org/licenses/>. | 136 ## see <http://www.gnu.org/licenses/>. |
134 @end example | 137 @end example |
135 | 138 |
136 Always include ChangeLog entries in changesets. After making your source | 139 Always include ChangeLog entries in changesets. After making your |
137 changes, record and briefly describe the changes in the nearest ChangeLog file | 140 source changes, record and briefly describe the changes in the nearest |
138 upwards in the directory tree. Use the previous entries as a template. Your | 141 ChangeLog file upwards in the directory tree. Use the previous entries |
139 entry should contain your name and email, and the path to the modified source | 142 as a template. Your entry should contain your name and email, and the |
140 file relative to the parent directory of the ChangeLog file. If there are more | 143 path to the modified source file relative to the parent directory of the |
141 functions in the file, you should also include the name of the modified function | 144 ChangeLog file. If there are more functions in the file, you should |
142 (in parentheses after file path). Example: | 145 also include the name of the modified function (in parentheses after |
146 file path). Example: | |
143 | 147 |
144 @example | 148 @example |
145 @group | 149 @group |
146 2008-04-02 David Bateman <dbateman@@free.fr> | 150 2008-04-02 David Bateman <dbateman@@free.fr> |
147 | 151 |
154 The ChangeLog entries should describe what is changed, not why. Any | 158 The ChangeLog entries should describe what is changed, not why. Any |
155 explanation of why a change is needed should appear as comments in the | 159 explanation of why a change is needed should appear as comments in the |
156 code, particularly if there is something that might not be obvious to | 160 code, particularly if there is something that might not be obvious to |
157 someone reading it later. | 161 someone reading it later. |
158 | 162 |
159 The preferred comment mark for places that may need further attention is FIXME. | 163 The preferred comment mark for places that may need further attention is |
164 FIXME. | |
160 | 165 |
161 @node Octave Sources (m-files) | 166 @node Octave Sources (m-files) |
162 @section Octave Sources (m-files) | 167 @section Octave Sources (m-files) |
163 | 168 |
164 Don't use tabs. Tabs cause trouble. If you are used to them, set up your | 169 Don't use tabs. Tabs cause trouble. If you are used to them, set up |
165 editor so that it converts tabs to spaces. Indent the bodies of the statement | 170 your editor so that it converts tabs to spaces. Indent the bodies of |
166 blocks. Recommended indent is 2 spaces. When calling functions, put spaces | 171 the statement blocks. Recommended indent is 2 spaces. When calling |
167 after commas and before the calling parentheses, like this: | 172 functions, put spaces after commas and before the calling parentheses, |
173 like this: | |
168 | 174 |
169 @example | 175 @example |
170 x = max (sin (y+3), 2); | 176 x = max (sin (y+3), 2); |
171 @end example | 177 @end example |
172 | 178 |
176 @example | 182 @example |
177 [sin(x), cos(x)] | 183 [sin(x), cos(x)] |
178 @end example | 184 @end example |
179 | 185 |
180 @noindent | 186 @noindent |
181 Here, putting spaces after @code{sin}, @code{cos} would result in a parse error. | 187 Here, putting spaces after @code{sin}, @code{cos} would result in a |
182 In indexing expression, do not put a space after the identifier (this | 188 parse error. In indexing expression, do not put a space after the |
183 differentiates indexing and function calls nicely). The space after comma is | 189 identifier (this differentiates indexing and function calls nicely). |
184 not necessary if index expressions are simple, i.e., you may write | 190 The space after comma is not necessary if index expressions are simple, |
191 i.e., you may write | |
185 | 192 |
186 @example | 193 @example |
187 A(:,i,j) | 194 A(:,i,j) |
188 @end example | 195 @end example |
189 | 196 |
192 | 199 |
193 @example | 200 @example |
194 A([1:i-1;i+1:n], XI(:,2:n-1)) | 201 A([1:i-1;i+1:n], XI(:,2:n-1)) |
195 @end example | 202 @end example |
196 | 203 |
197 Use lowercase names if possible. Uppercase is acceptable for variable names | 204 Use lowercase names if possible. Uppercase is acceptable for variable |
198 consisting of 1-2 letters. Do not use mixed case names. Function names must be | 205 names consisting of 1-2 letters. Do not use mixed case names. Function |
199 lowercase. Function names are global, so choose them wisely. | 206 names must be lowercase. Function names are global, so choose them |
207 wisely. | |
200 | 208 |
201 Always use a specific end-of-block statement (like @code{endif}, | 209 Always use a specific end-of-block statement (like @code{endif}, |
202 @code{endswitch}) rather than generic @code{end}. Enclose the @code{if}, | 210 @code{endswitch}) rather than generic @code{end}. |
203 @code{while}, @code{until} and @code{switch} conditions in parentheses, | 211 |
204 like in C: | 212 Enclose the @code{if}, @code{while}, @code{until} and @code{switch} |
213 conditions in parentheses, like in C: | |
205 | 214 |
206 @example | 215 @example |
207 @group | 216 @group |
208 if (isvector (a)) | 217 if (isvector (a)) |
209 s = sum(a); | 218 s = sum(a); |
210 endif | 219 endif |
211 @end group | 220 @end group |
212 @end example | 221 @end example |
213 | 222 |
214 @noindent | 223 @noindent |
215 Do not do this, however, with @code{for}: | 224 Do not do this, however, with the iteration counter portion of a |
225 @code{for} statement. Write: | |
216 | 226 |
217 @example | 227 @example |
218 @group | 228 @group |
219 for i = 1:n | 229 for i = 1:n |
220 b(i) = sum (a(:,i)); | 230 b(i) = sum (a(:,i)); |
223 @end example | 233 @end example |
224 | 234 |
225 @node C++ Sources | 235 @node C++ Sources |
226 @section C++ Sources | 236 @section C++ Sources |
227 | 237 |
228 Don't use tabs. Tabs cause trouble. If you are used to them, set up your | 238 Don't use tabs. Tabs cause trouble. If you are used to them, set up |
229 editor so that it converts tabs to spaces. Format function headers like this: | 239 your editor so that it converts tabs to spaces. Format function headers |
240 like this: | |
230 | 241 |
231 @example | 242 @example |
232 @group | 243 @group |
233 static bool | 244 static bool |
234 matches_patterns (const string_vector& patterns, int pat_idx, | 245 matches_patterns (const string_vector& patterns, int pat_idx, |
235 int num_pat, const std::string& name) | 246 int num_pat, const std::string& name) |
236 @end group | 247 @end group |
237 @end example | 248 @end example |
238 | 249 |
239 @noindent | 250 @noindent |
240 The function name should start in column 1, and multi-line argument lists should | 251 The function name should start in column 1, and multi-line argument |
241 be aligned on the first char after the open parenthesis. You should put a space | 252 lists should be aligned on the first char after the open parenthesis. |
242 after the left open parenthesis and after commas, for both function definitions | 253 You should put a space after the left open parenthesis and after commas, |
243 and function calls. | 254 for both function definitions and function calls. |
244 | 255 |
245 Recommended indent is 2 spaces. When indenting, indent the statement after | 256 Recommended indent is 2 spaces. When indenting, indent the statement |
246 control structures (like @code{if}, @code{while}, etc.). If there is a compound | 257 after control structures (like @code{if}, @code{while}, etc.). If there |
247 statement, indent @emph{both} the curly braces and the body of the statement (so | 258 is a compound statement, indent @emph{both} the curly braces and the |
248 that the body gets indented by @emph{two} indents). Example: | 259 body of the statement (so that the body gets indented by @emph{two} |
260 indents). Example: | |
249 | 261 |
250 @example | 262 @example |
251 @group | 263 @group |
252 if (have_args) | 264 if (have_args) |
253 @{ | 265 @{ |
261 | 273 |
262 @noindent | 274 @noindent |
263 If you have nested @code{if} statements, use extra braces for extra | 275 If you have nested @code{if} statements, use extra braces for extra |
264 clarification. | 276 clarification. |
265 | 277 |
266 Split long expressions in such a way that a continuation line starts with an | 278 Split long expressions in such a way that a continuation line starts |
267 operator rather than identifier. If the split occurs inside braces, | 279 with an operator rather than identifier. If the split occurs inside |
268 continuation should be aligned with the first char after the innermost braces | 280 braces, continuation should be aligned with the first char after the |
269 enclosing the split. Example: | 281 innermost braces enclosing the split. Example: |
270 | 282 |
271 @example | 283 @example |
272 @group | 284 @group |
273 SVD::type type = ((nargout == 0 || nargout == 1) | 285 SVD::type type = ((nargout == 0 || nargout == 1) |
274 ? SVD::sigma_only | 286 ? SVD::sigma_only |
275 : (nargin == 2) ? SVD::economy : SVD::std); | 287 : (nargin == 2) ? SVD::economy : SVD::std); |
276 @end group | 288 @end group |
277 @end example | 289 @end example |
278 | 290 |
279 @noindent | 291 @noindent |
280 Consider putting extra braces around a multiline expression to make it more | 292 Consider putting extra braces around a multiline expression to make it |
281 readable, even if they are not necessary. Also, do not hesitate to put extra | 293 more readable, even if they are not necessary. Also, do not hesitate to |
282 braces anywhere if it improves clarity. | 294 put extra braces anywhere if it improves clarity. |
283 | 295 |
284 Try declaring variables just before they're needed. Use local variables of | 296 Declare variables just before they're needed. Use local variables of |
285 blocks - it helps optimization. Don't write multi-line variable declaration | 297 blocks---it helps optimization. Don't write multi-line variable |
286 with a single type specification and multiple variables. If the variables don't | 298 declaration with a single type specification and multiple variables. If |
287 fit on single line, repeat the type specification. Example: | 299 the variables don't fit on single line, repeat the type specification. |
300 Example: | |
288 | 301 |
289 @example | 302 @example |
290 @group | 303 @group |
291 octave_value retval; | 304 octave_value retval; |
292 | 305 |
295 | 308 |
296 double d1, d2; | 309 double d1, d2; |
297 @end group | 310 @end group |
298 @end example | 311 @end example |
299 | 312 |
300 Use lowercase names if possible. Uppercase is acceptable for variable names | 313 Use lowercase names if possible. Uppercase is acceptable for variable |
301 consisting of 1-2 letters. Do not use mixed case names. | 314 names consisting of 1-2 letters. Do not use mixed case names. |
302 | 315 |
303 Try to use Octave's types and classes if possible. Otherwise, try to use C++ | 316 Use Octave's types and classes if possible. Otherwise, use the C++ |
304 standard library. Use of STL containers and algorithms is encouraged. Use | 317 standard library. Use of STL containers and algorithms is encouraged. |
305 templates wisely to reduce code duplication. Avoid comma expressions, labels | 318 Use templates wisely to reduce code duplication. Avoid comma |
306 and gotos, and explicit typecasts. If you need to typecast, use the modern C++ | 319 expressions, labels and gotos, and explicit typecasts. If you need to |
307 casting operators. In functions, try to reduce the number of @code{return} | 320 typecast, use the modern C++ casting operators. In functions, minimize |
308 statements - use nested @code{if} statements if possible. | 321 the number of @code{return} statements---use nested @code{if} statements |
322 if possible. | |
309 | 323 |
310 @node Other Sources | 324 @node Other Sources |
311 @section Other Sources | 325 @section Other Sources |
312 Apart from C++ and Octave language (m-files), Octave's sources include files | 326 Apart from C++ and Octave language (m-files), Octave's sources include |
313 written in C, Fortran, M4, Perl, Unix shell, AWK, Texinfo and @TeX{}. There are | 327 files written in C, Fortran, M4, Perl, Unix shell, AWK, Texinfo and |
314 not many rules to follow when using these other languages; some of them are | 328 @TeX{}. There are not many rules to follow when using these other |
315 summarized below. In any case, the golden rule is: if you modify a source | 329 languages; some of them are summarized below. In any case, the golden |
316 file, try to follow any conventions you can detect in the file or other similar | 330 rule is: if you modify a source file, try to follow any conventions you |
317 files. | 331 can detect in the file or other similar files. |
318 | 332 |
319 For C you should obviously follow all C++ rules that can apply. | 333 For C you should obviously follow all C++ rules that can apply. |
320 | 334 |
321 If you happen to modify a Fortran file, you should stay within Fortran 77 | 335 If you modify a Fortran file, you should stay within Fortran 77 with |
322 with common extensions like @code{END DO}. Currently, we want all sources | 336 common extensions like @code{END DO}. Currently, we want all sources to |
323 to be compilable with the f2c and g77 compilers, without special flags if | 337 be compilable with the f2c and g77 compilers, without special flags if |
324 possible. This usually means that non-legacy compilers also accept the sources. | 338 possible. This usually means that non-legacy compilers also accept the |
325 | 339 sources. |
326 The M4 macro language is mainly used for Autoconf configuration files. You | 340 |
327 should follow normal M4 rules when contributing to these files. Some M4 files | 341 The M4 macro language is mainly used for Autoconf configuration files. |
328 come from external source, namely the Autoconf archive | 342 You should follow normal M4 rules when contributing to these files. |
343 Some M4 files come from external source, namely the Autoconf archive | |
329 @url{http://autoconf-archive.cryp.to}. | 344 @url{http://autoconf-archive.cryp.to}. |
330 | 345 |
331 If you give a code example in the documentation written in Texinfo with the | 346 If you give a code example in the documentation written in Texinfo with |
332 @code{@@example} environment, you should be aware that the text within such an | 347 the @code{@@example} environment, you should be aware that the text |
333 environment will not be wrapped. It is recommended that you keep the lines | 348 within such an environment will not be wrapped. It is recommended that |
334 short enough to fit on pages in the generated pdf or ps documents. Here is a | 349 you keep the lines short enough to fit on pages in the generated pdf or |
335 ruler (in an @code{@@example} environment) for finding the appropriate line | 350 ps documents. Here is a ruler (in an @code{@@example} environment) for |
336 width: | 351 finding the appropriate line width: |
337 | 352 |
338 @example | 353 @example |
339 @group | 354 @group |
340 1 2 3 4 5 6 | 355 1 2 3 4 5 6 |
341 123456789012345678901234567890123456789012345678901234567890 | 356 123456789012345678901234567890123456789012345678901234567890 |