HACKING 5.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
Bootstraping:
=============

Some files in SPOT's source tree are generated.  They are distributed
so that users do not need to tools to rebuild them, but we don't keep
all of them under CVS because it can generate lots of changes or
conflicts.

Here are the tools you need to bootstrap the CVS tree, or more
generally if you plan to regenerate some of the generated files.
11

12
  GNU Autoconf 2.57
13
  GNU Automake 1.8
14
15
  GNU Flex (the version probably doesn't matter much, we used 2.5.4)
  The CVS version of GNU Bison (called 1.875b at the time of writing)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
16
  SWIG 1.3.19
17
  Doxygen 1.3.5
18
19
20
21
22

Bootstrap the CVS tree by running

  autoreconf -vfi

23
and then go on with the usual
24
25
26
27

  ./configure
  make

28

29
30
31
32
Coding conventions:
===================

Here are the conventions we follow in Spot, so that the code looks
33
34
35
36
37
38
homogeneous.  Please follow these strictly.  Since this is free
software, uniformity of the code matters a lot.  Most of these
conventions are derived from the GNU Coding Standards
(http://www.gnu.org/prep/standards.html) with the notable exception
that we do not put a space before the opening parenthesis in function
calls (this is hardly readable when chaining method calls).
39
40
41
42
43
44
45
46
47
48

Comments
--------

  * The language to use is American.

  * When comments are sentences, they should start with a capital and
    end with a dot.  Dots that end sentences should be followed by two
    spaces (i.e., American typing convention), like in this paragraph.

49
50
51
  * Prefer C++-style comments (// foo) to C-style comments (/* foo */).
    Use /// for Doxygen comments.

52
53
54
Formating
---------

55
  * Braces are always on their own line.
56
57
58
59
60

  * Text within braces is two-space indented.

    {
      f(12);
61

62
63
64
65
66
67
68
69
70
71
72
73
    }

  * Anything after a control statement is two-space indented.  This
    includes braces.

    if (test)
      {
        f(123);
	while (test2)
	  g(456);
      }

74
  * Braces from function/structure/enum/class/namespace definitions
75
76
77
78
79
80
81
82
83
84
85
    are not indented.

    class foo
    {
    public:
      Foo();
    protected:
      static int get_mumble();
    };

  * The above corresponds to the `gnu' indentation style under Emacs.
86
87
88

  * Put return types and linkage specifiers on their own line in
    function/method _definitions_:
89
90
91
92
93
94
95
96
97

    static int
    Foo::get_mumble()
    {
      return 2;
    }

    This makes it easier to grep functions in the code.

98
99
100
    Function/method declaration are usually written on one line:

    int get_bar(int i);
101

102
  * Put a space before the opening parenthesis in control statements
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

    if (test)
      {
        do
	  {
	    something();
	  }
	while (0);
      }

  * No space before parentheses in function calls.
    (`some()->foo()->bar()' is far more readable than
    `some ()->foo ()->bar ()' is)

  * No space after opening or before closing parentheses, however
    put a space after commas (as in english).
119

120
    func(arg1, arg2, arg3);
121

122
123
124
125
126
127
128
129
130
  * No useless parentheses in return statements.

    return 2;    (not `return (2);')

  * Spaces around infix binary or ternary operators:

    2 + 2;
    a = b;
    a <<= (3 + 5) * 3 + f(67 + (really ? 45 : 0));
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  * No space after prefix unary operators, or befor postfix unary operators:

    if (!test && y++ != 0)
      {
        ++x;
      }

  * When an expression spans over several lines, split it before
    operators.  If it's inside a parenthesis, the following lines
    should be 1-indented w.r.t. the opening parenthesis.

    if (foo_this_is_long && bar > win(x, y, z)
        && !remaining_condition)
      {
        ...
      }

149
150
  * No line should be larger than 80 columns.
    If a line takes more than 80 columns, split it or rethink it.
151

152
  * Labels or case statements are back-indented by two spaces,
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
153
    without space before the `:'.
154

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    if (something)
      {
      top:
        bar = foo();
        switch (something_else)
	  {
	  case first_case:
	    f();
	    break;
	  case second_case:
	    g();
	    break;
	  default:
	    goto top;
	  }
      }

172
173
174
175
176
177
178
179
180
Naming
======

  * Functions, methods, types, classes, etc. are named with lowercase
    letters, using an underscore to separate words.

      int compute_this_and_that();

      class this_is_a_class;
181

182
183
184
185
      typedef int int_array[];

    That is the style used in STL.

186
  * Private members end with an underscore.
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

    class my_class
    {
    public:
      ...
      int get_val() const;
    private:
      int name_;
    };

  * Identifiers (even internal) starting with `_' are best avoided
    to limit clashes with system definitions.

  * Template arguments use capitalized name, with joined words.

    template <class T, int NumberOfThings>
    class foo
    {
      ...
    };

208
  * Enum members also use capitalized name, with joined words.
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

  * C Macros are all uppercase.

  * Pointers and references are part of the type, and should be put
    near the type, not near the variable.

      int* p;        // not `int *p;'
      list& l;       // not `list &l;'
      void* magic(); // not `void *magic();'

  * Do not declare many variables on one line.
    Use
      int* p;
      int* q;
    instead of
      int *p, *q;
    The former declarations also allow you to describe each variable.

  * The include guard for src/somedir/foo.hh is
    SPOT_SOMEDIR_FOO_HH