aboutsummaryrefslogtreecommitdiff
path: root/doc/Coding_style
diff options
context:
space:
mode:
Diffstat (limited to 'doc/Coding_style')
-rw-r--r--doc/Coding_style247
1 files changed, 213 insertions, 34 deletions
diff --git a/doc/Coding_style b/doc/Coding_style
index d0eba0d..0c10170 100644
--- a/doc/Coding_style
+++ b/doc/Coding_style
@@ -1,45 +1,224 @@
1The coding style is almost the same as i blackbox. 1Use hard tab for indentation. (size 4)
2Instead of 2 spaces there is tab. 2Spaces between ","
3It might look strange now in some places, that is because 3ex: 1, 2, 3, 4
4the code hasnt been "translated" to tab 100% yet. 4
5Use a tab size of 2 and you will be fine. 5if/else-statements:
6 6An else clause is joined to any preceding close curly brace
7note if-statement: 7that is part of its if.
8 8
9 if ( stuff ) 9if (....) {
10 function(stuff, more stuff, 10 ....
11 more, even more); 11} else {
12 else 12 ....
13 morefunction( stuff, more stuff 13}
14 stuff, 14if the line needs to be splited up, right after an if-statement
15 stuff,
16 stuff);
17
18if the functionline needs to be split up, like above, right after a if-statement
19use { and }, so its clear when the if-statement ends. 15use { and }, so its clear when the if-statement ends.
20It should look like this 16ex:
17if (...) {
18 function(.....,
19 ......, .... );
20}
21 21
22 if ( stuff ) { 22This is ok:
23 function(stuff, more stuff, 23if (...)
24 more, even more); 24 shortline(...);
25 } else { 25
26 morefunction( stuff, more stuff 26
27 stuff, 27while-statement:
28 stuff, 28
29 stuff); 29while (...) {
30 } 30 ....
31 31}
32The includeguards: 32
33_FILENAME_HH_ 33for-statement:
34
35for (init; condition; update) {
36 ....
37}
38
39for (longinit;
40 longcondition;
41 longupdate ) {
42 ....
43}
44alt form:
45
46init;
47for (; condition; update) {
48 ....
49}
50
51do-statement:
34 52
53do {
54 ....
55} while (...);
56
57switch-statement:
58should always have a default value.
59Enum values is an exception, they should not have a default: , when you add
60new values to an enum you might forget to add them to switch statement.
61
62switch (...) {
63 case ...:
64 ...;
65 break;
66 case ...: {
67 ...;
68 } break;
69 case ...:
70 ...;
71 default:
72 ....;
73 break;
74}
75
76goto-statement:
77DONT USE IT!
78
79
80Include guards:
81For files with namespace:
82#ifndef NAMESPACE_FILENAME_HH
83#define NAMESPACE_FILENAME_HH
84....
85
86#endif //NAMESPACE_FILENAME_HH
87<eof>
88
89Without namespace:
90#ifndef FILENAME_HH
91#define FILENAME_HH
92....
93
94#endif //FILENAME_HH
95
96<eof>
97
98preprocessors:
99The # of all preprocessor commands must always be in column 1, and never use
100indentation for preprocessor directives
101
102They should always have a // PREPROCESSOR to mark where they end
103#ifdef DEBUG
104...
105...
106#endif //DEBUG
107
108Don't use preprocessors for constants or macro-functions, they can be
109cryptic and sometime make it hard to debug.
110
111
112functions:
113The name starts with a lowercase and then a uppercase for name separation:
114void functionWithAName(...) {
115 ...;
116}
35 117
36Function comments: 118Function comments:
37//------------ function name --------
38// This do that and that 119// This do that and that
39// Returns this on success else 120// Returns this on success else
40// this on failure. 121// this on failure.
41// TODO: if there is something to do. 122// TODO: if there is something to do.
42//----------------------------------- 123void functionDoes(...) {
43type classname::function(...) {
44 124
45} 125}
126Comments:
127Use // on few line comments.
128Use
129/*
130...
131...
132*/
133when there are a lot to comment
134
135Class:
136Order: public, protected and then private
137Class names always starts with a big letter.
138Class data members are prefixed by m_ , static data members are prefixed with s_ .
139Class member function will be organized according to creator,
140manipulator and accessors categories.
141
142class Classname:public AnotherClass {
143public:
144 //1. public enums, structs
145
146 //2. constructors and destructor
147
148 //3. manipulators
149
150 //4. accessors
151
152protected:
153 //1. enums, structs
154
155 //2. functions
156
157 //3. variables
158
159private:
160 //1. enums, structs
161
162 //2. functions
163
164 //3. variables
165};
166
167
168struct follows the class style.
169
170namespace:
171namespace TheName {
172...;
173...;
174}; //end namespace TheName
175
176Don't use "using namespace thenamespace;" in header-file
177We don't want to force the other files, that include the file, a namespace.
178
179
180try/catch-statement:
181
182try {
183 ....;
184} catch (...) {
185 ....;
186}
187
188Variables:
189Avoid variables that contain mixtures of the numbers 0 & l and the letters O
190and 1, because they are hard to tell apart.
191Having a type name and a variable differing in only in case (such as:
192 String string;) is permitted, but discouraged.
193
194Use lowercase for variables and use _ to separate names, ex:
195int number_of_screens;
196int num_colors;
197
198
199All constants must be in Upper case letters.
200
201enums must be in uppercase letters and not in file scope:
202enum {WHITE, RED, BLUE};
203
204Other:
205
206if (strcmp(...) == 0) //good
207if (!strcmp()) //bad
208
209Don't create free-functions, encapsulate them in a namespace or a class
210and name filenames so it's clear what they hold so it's easier to find
211functions, classes and other stuff.
212
213
214ChangeLog format:
215*year/month/day:
216 * whats changed (who changed it)
217 which file
218
219ex:
220
221*02/01/01:
222 * Fixed bug workspace change (TheDude)
223 Workspace.cc
224