-
Notifications
You must be signed in to change notification settings - Fork 20
/
guidelines.txt
188 lines (141 loc) · 4.28 KB
/
guidelines.txt
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
In this file you can find few guidelines for developers. We don't give in-depth details, fell free to inspire you from existing code
and to use things that can make the code easy to read. If their is any lake, send us a mail on the devlist (patate-devel@lists.gforge.inria.fr).
******
Naming
******
General Naming Rules
********************
Function names, variable names, and filenames should be descriptive. In most of case use the CamelCase notation.
File Names
**********
Use the lowerCamelCase notation : myFileIsCool.cpp
Use .h for headers, .cpp for sources. If you are using templates use .hpp for the implemented part.
Type Names
**********
Use the UpperCamelCase notation : MyClassIsReallyCool. Execept for enums, see below.
Variable Names
**************
Use the lowerCamelCase notation. If you want, hungarian notation is tolerated.
Use m_ for members variables.
Use _ for function params.
void function(float _scale)
{
float scale = _scale;
doSomething(scale);
m_scale = scale;
}
With hungarian notation :
void function(float _fScale)
{
float fScale = _fScale;
doSomething(fScale);
m_fScale = fScale;
}
Constant Name
*************
Use a k followed by mixed case : kThisIsAConstant
Function Names
**************
Regular functions have mixed case; accessors and mutators match the name of the variable. You can use get/set suffix if you want.
Namespace Names
***************
Namespace names can be in UpperCamelStyle for important or in lowerCamelCase for smaller namespaces.
For example :
namespace Granaille
{
//many things
namespace internal
{
//few things
}
}
Enumerator Names
****************
Use this style : MY_ENUM.
enum COOL_ENUM
{
VALUE1 = 0,
VALUE2 = 1,
NBVALUE
}
Macro Names
***********
Same as enumerator : MY_MACRO_IS_COOL.
Exceptions to Naming Rules
**************************
If you are naming something that is analogous to an existing C or C++ entity then you can follow the existing naming convention scheme.
**********
Formatting
**********
This are basics rules for a better reading of the code. We'll don't give more details. Feel free to llok existing code and respect those basic rules.
Spaces versus Tabs
******************
We use spaces for indentation (4 spaces for 1 indent level). Do not use tabs in your code. You should set your editor to emit spaces when you hit the tab key.
Brackets
********
Use the Allman style :
void function()
{
while(condition)
{
doSomething();
}
}
For empty functions put both brackets on the same line :
void emptyFunction()
{}
Function Declarations and Definitions
*************************************
Return type on the same line as function name except for templates. Parameters on the same line if the line length is not to long.
Functions look like this:
ReturnType ClassName::FunctionName(Type par_name1, Type par_name2)
{
DoSomething();
...
}
If you have too much arguments on one line:
ReturnType ClassName::ReallyLongFunctionName(Type par_name1, Type par_name2,
Type par_name3)
{
DoSomething();
...
}
You can also put one argument per line if the function name is very long and have many args.
Class Format
************
There is no order and no indentations for public, protected, private sections. you can group
methods by theme if you want. Prefer putting members variables at the end of the class.
Be sure to separate variables and methods even if they are in the same section.
class MyClass : public OtherClass
{
public: // No indent!
MyClass(); // Regular 2 space indent.
explicit MyClass(int var);
~MyClass() {}
void someFunction();
void someFunctionThatDoesNothing()
{}
private:
bool someInternalFunction();
private: // Private variables separated from privat methods
int _var;
int _otherVar_;
};
Namespace Formatting
********************
Namespaces do not add an extra level of indentation. Use:
namespace toto
{
void function() //No extra indentation within namespace.
{
...
}
}
Line Length
***********
There is no length limit. The developer does with his felling but be moderate and don't have infinite line length...