File: CodingRules

package info (click to toggle)
siconos 4.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 82,496 kB
  • sloc: cpp: 159,693; ansic: 108,665; fortran: 33,248; python: 20,709; xml: 1,244; sh: 385; makefile: 226
file content (72 lines) | stat: -rw-r--r-- 2,245 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- org -*-

* Names

 - We are using the CamelCas naming convention. In C++, the first
   letter is capitalized for class names, whereas it is not for method
   names. Private attributes begin with an underscore followed by a
   lower case letter.  Underscores are forbidden in class and method
   names.

 - SWIG is used to generate Python bindings. It processes headers
   files to do its magic. Therefore the parameter names in headers are
   not meaningless.

* code style c, c++ 

 - cf astyle documentation. We use ansi style with
   unpad parenthesis and 2 spaces for indentation

   astyle --style=ansi -U -v -s2

* code style python

  we prefer pep8 style
  use [[../Tools/emacs/siconos-dot-emacs.el]]


* Pointers
 - We use a lot of shared_ptr (SP in Siconos) but make sure to not abuse them
   since they come with a cost. For instant, in most case you should not pass
   a SP as an argument. When a variable is used only locally or temporary, it
   also usually not needed. The same applies to private attributes in classes
   that are really private (not used outside the class).

* Debug
 - Do not use assert in constructor. Usually you need to do checks and throw
   an exception if something is wrong. Furthermore in python it will either
   kill the interpreter or fail silently.

* Documentation
We are using Doxygen to document the code. Please document a function or a
method before its signature. Doxygen uses '/**' and '*/' as delimiter.
- how to document function:

/** function to compare bar and fun
* \param bar an integer
* \param fun an integer
* \return 1 if fun > bar, 0 otherwise
*/
unsigned int foo(int bar, int fun);

for the parameter, you can also also specify the direction using [in], [out]
or [in, out]. Example:
/** function to copy and multiply by a scalar
* \param[in] x the input vector
* \param[out] y the output vector
* \param coeff the coefficient to apply
*/
void myaxpy(double * x, double * y, double coeff)

- how to document variables:
/** used to compute foo */
unsigned int bar;

- how to document a class:
provide a brief description:
/** \brief This class describe bar */

and a detailed one
/** This class is meant to ... blablabla ... */

document all the attributes and the functions