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, 208 insertions, 39 deletions
diff --git a/doc/Coding_style b/doc/Coding_style
index d0eba0d..47bd173 100644
--- a/doc/Coding_style
+++ b/doc/Coding_style
@@ -1,45 +1,214 @@
1The coding style is almost the same as i blackbox. 1Use 4 space indent
2Instead of 2 spaces there is tab. 2Spaces between ","
3It might look strange now in some places, that is because 3ex: 1, 2, a, 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:
21 17if (...) {
22 if ( stuff ) { 18 function(.....,
23 function(stuff, more stuff, 19 ......, .... );
24 more, even more); 20}
25 } else { 21
26 morefunction( stuff, more stuff 22This is ok:
27 stuff, 23if (...)
28 stuff, 24 shortline(...);
29 stuff); 25
30 } 26
31 27while-statement:
32The includeguards: 28
33_FILENAME_HH_ 29while (...) {
30 ....
31}
32
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:
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
76Include guards:
77For files with namespace:
78#ifndef NAMESPACE_FILENAME_HH
79#define NAMESPACE_FILENAME_HH
80....
81
82#endif //NAMESPACE_FILENAME_HH
83<eof>
84
85Without namespace:
86#ifndef FILENAME_HH
87#define FILENAME_HH
88....
89
90#endif //FILENAME_HH
91
92<eof>
93
94preprocessors:
95The # of all preprocessor commands must always be in column 1, and never use
96indentation for preprocessor directives
97
98They should always have a // PREPROCESSOR to mark where they end
99#ifdef DEBUG
100...
101...
102#endif //DEBUG
34 103
104Don't use preprocessors for constants or macro-functions, they can be
105cryptic and sometime make it hard to debug.
35 106
107
108functions:
109The name starts with a lowercase and then a uppercase for name separation:
110void functionWithAName(...) {
111 ...;
112}
113
114Use Javadoc style for function description (see www.doxygen.org)
36Function comments: 115Function comments:
37//------------ function name -------- 116/**
38// This do that and that 117 This do that and that
39// Returns this on success else 118 @return this on success else this on failure.
40// this on failure. 119 TODO: if there is something to do.
41// TODO: if there is something to do. 120*/
42//----------------------------------- 121void functionDoes(...) {
43type classname::function(...) { 122
123}
124
125Class:
126Order: public, protected and then private
127Class names always starts with a big letter.
128Class data members are prefixed by m_ , static data members are prefixed with s_ .
129Class member function will be organized according to creator,
130manipulator and accessors categories.
131
132class Classname:public AnotherClass {
133public:
134 //1. public enums, structs
135
136 //2. constructors and destructor
137
138 //3. manipulators
139
140 //4. accessors
141
142protected:
143 //1. enums, structs
144
145 //2. functions
146
147 //3. variables
148
149private:
150 //1. enums, structs
151
152 //2. functions
153
154 //3. variables
155};
156
157
158struct follows the class style.
159
160namespace:
161namespace TheName {
162...;
163...;
164}; //end namespace TheName
165
166Don't use "using namespace thenamespace;" in header-file
167We don't want to force the other files, that include the file, a namespace.
168
169
170try/catch-statement:
44 171
172try {
173 ....;
174} catch (...) {
175 ....;
45} 176}
177
178Variables:
179Avoid variables that contain mixtures of the numbers 0 & l and the letters O
180and 1, because they are hard to tell apart.
181Having a type name and a variable differing in only in case (such as:
182 String string;) is permitted, but discouraged.
183
184Use lowercase for variables and use _ to separate names, ex:
185int number_of_screens;
186int num_colors;
187
188
189All constants must be in Upper case letters.
190
191enums must be in uppercase letters and not in file scope:
192enum {WHITE, RED, BLUE};
193
194Other:
195
196if (strcmp(...) == 0) //good
197if (!strcmp()) //bad
198
199Don't create free-functions, encapsulate them in a namespace or a class
200and name filenames so it's clear what they hold so it's easier to find
201functions, classes and other stuff.
202
203
204ChangeLog format:
205*year/month/day:
206 * whats changed (who changed it)
207 which file
208
209ex:
210
211*02/01/01:
212 * Fixed bug workspace change (TheDude)
213 Workspace.cc
214