Subversion Repositories gelsvn

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 bj 1
Andreas Bærentzen, 
2
December 2001
3
 
4
----------------------------------------------------------------------
5
CODING CONVENTIONS
6
----------------------------------------------------------------------
7
 
8
Coding conventions are very important if the source code is to remain
9
legible and tidy. Very strict conventions, however, will require too
10
much work of the programmer, and (if the programmer is myself) he will 
11
start to ignore some of the conventions in order to do things more
12
quickly, and then the card house topples.
13
 
14
Nothing that imposes too much work should be made a coding
15
convention. For instance, a standard comment before each function
16
definition sounds like a good idea, but even with a template, it is
17
cumbersome to add and maintain these chunks of text, so I choose to
136 jab 18
omit them. However, Doxygen comments are added whereever I get around to it.
2 bj 19
 
20
The philosophy behind the conventions below is that they should simply 
21
be standard ways of doing what a programmer does anyway and that they
22
should add only very little extra work.
23
 
24
USE OF CASE AND SPECIAL CHARACTERS
25
------------------------------
26
 
27
* Abbreviations are used only where the names would otherwise be
28
ludicrously long.
29
 
30
* Names of constants are all uppercase letters. Underscores are used to
31
combine words, e.g. `MAX_LEVEL'
32
 
33
* Names of classes and other new types are in lower case but
136 jab 34
inter-capitalized, e.g. `class MyClass'
2 bj 35
 
36
* The names of functions are lower case. Words are combined with
37
underscores, e.g. `int get_max()'
38
 
39
FUNCTION NAMING
40
------------------------------
41
 
42
* Words used
43
 
44
The words `get' and `set' are used in the names of functions that
45
assigns or retrieves the value of some state variable in a class.
46
 
47
E.g.
48
 
49
get_level
50
set_level
51
 
52
The words `find', `remove', `insert' are used in the names of
53
functions that access a database.
54
 
55
E.g.
56
 
57
find_node
58
remove_node
59
insert_node
60
 
61
The word `create' is used in the name of a function that creates and
62
returns a member of a class, e.g.
63
 
64
create_inquirer
65
 
66
The word `inquirer' is used in the names of functions that access
67
data structures. E.g.
68
 
69
OctreeInquirer
70
 
71
COMMENTING
72
------------------------------
73
 
74
* Comments are used where appropriate. DOC++ comments are used 
75
for all class members in .h files. There are no comments used
76
purely for aestethical or ``typographical'' reasons.
77
...
78
 
79
At some point I may add a standard file header. Could contain CVS
80
information perhaps.
81
 
82
FUNCTION ARGUMENTS
83
------------------------------
84
 
85
* Constructor arguments. If a class X contains a variable y that is
86
initialized in the contructor of X, then the argument to the
87
constructor should be _y, that is
88
 
89
X::X(_y): y(_y) {}
90
 
91
* Usually a function takes arguments that are constant and ``call by
92
reference'' arguments that may be modified. The constant arguments
93
should come first, then the modifiable. E.g.
94
 
95
        foo(const MyClass&, int, float&);
96
 
97
has two constant arguments followed by a float which is passed by
98
reference.
99
 
100
FILE (NAMING) CONVENTIONS
101
------------------------------
102
 
103
* All classes that are not auxiliary (i.e. used only by one particular
104
other class) have a header file of their own. 
105
 
106
* The name of the header file is that of the class + `.h'
107
 
108
* All non-auxiliary classes with one or more functions that are not
109
inline have a definition file of their own.
110
 
136 jab 111
* The name of the definition file is that of the class + `.cpp'
2 bj 112
 
136 jab 113
* The #define <macro> in the include guard uses the name of the
114
  namespace followed by the name of the file - capitalized and with dot
115
  replaced by underscore.	This string is also preceeded and followed by
116
	two underscores. For instance,
2 bj 117
 
136 jab 118
#ifndef __CGLA__ARITHVECFLOAT_H__
119
#define __CGLA__ARITHVECFLOAT_H__
2 bj 120
 
121
... code ....
122
 
123
#endif
124
 
136 jab 125
  Not all code adheres to this convention yet.
126