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