diff options
author | fluxgen <fluxgen> | 2002-07-23 16:10:49 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-07-23 16:10:49 (GMT) |
commit | 012741f7e867c1e985e64af7ad1f1f5d4d39368b (patch) | |
tree | febe76c9897ea060df2bd7e73778563793ee0805 /doc | |
parent | 4bc5d80ba7da019cfeeded6e3fc75bece963a49d (diff) | |
download | fluxbox_lack-012741f7e867c1e985e64af7ad1f1f5d4d39368b.zip fluxbox_lack-012741f7e867c1e985e64af7ad1f1f5d4d39368b.tar.bz2 |
huge update
Diffstat (limited to 'doc')
-rw-r--r-- | doc/Coding_style | 234 |
1 files changed, 194 insertions, 40 deletions
diff --git a/doc/Coding_style b/doc/Coding_style index d57dcf1..0cd9211 100644 --- a/doc/Coding_style +++ b/doc/Coding_style | |||
@@ -1,58 +1,212 @@ | |||
1 | The coding style is almost the same as i blackbox. | 1 | Use hard tab for indentation. (size 4) |
2 | Instead of 2 spaces there is tab. | 2 | Spaces between "," |
3 | Use a tab size of 2 or 4 and you will be fine. | 3 | ex: 1, 2, 3, 4 |
4 | 4 | ||
5 | if-statements: | 5 | if/else-statements: |
6 | 6 | An else clause is joined to any preceding close curly brace | |
7 | if ( stuff ) | 7 | that is part of its if. |
8 | function(stuff, more stuff, | 8 | |
9 | more, even more); | 9 | if (....) { |
10 | else | 10 | .... |
11 | morefunction( stuff, more stuff | 11 | } else { |
12 | stuff, | 12 | .... |
13 | stuff, | 13 | } |
14 | stuff); | 14 | if the line needs to be splited up, right after an if-statement |
15 | |||
16 | if the functionline needs to be split up, like above, right after an if-statement | ||
17 | use { and }, so its clear when the if-statement ends. | 15 | use { and }, so its clear when the if-statement ends. |
18 | It should look like this | 16 | ex: |
17 | if (...) { | ||
18 | function(....., | ||
19 | ......, .... ); | ||
20 | } | ||
19 | 21 | ||
20 | if ( stuff ) { | 22 | This is ok: |
21 | function(stuff, more stuff, | 23 | if (...) |
22 | more, even more); | 24 | shortline(...); |
23 | } else { | 25 | |
24 | morefunction( stuff, more stuff | 26 | |
25 | stuff, | 27 | while-statement: |
26 | stuff, | 28 | |
27 | stuff); | 29 | while (...) { |
28 | } | 30 | .... |
29 | 31 | } | |
30 | If a line need to be splited in an if-statement then it should use two | 32 | |
31 | tab for indent next row in if-statement like this: | 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 | goto-statement: | ||
77 | DONT USE IT! | ||
78 | |||
79 | |||
80 | Include guards: | ||
81 | For files with namespace: | ||
82 | #ifndef NAMESPACE_FILENAME_HH | ||
83 | #define NAMESPACE_FILENAME_HH | ||
84 | .... | ||
85 | |||
86 | #endif //NAMESPACE_FILENAME_HH | ||
87 | <eof> | ||
88 | |||
89 | Without namespace: | ||
90 | #ifndef FILENAME_HH | ||
91 | #define FILENAME_HH | ||
92 | .... | ||
93 | |||
94 | #endif //FILENAME_HH | ||
95 | |||
96 | <eof> | ||
32 | 97 | ||
33 | if ( longline && longline && longling && | 98 | preprocessors: |
34 | longline && longline && longline) | 99 | The # of all preprocessor commands must always be in column 1, and never use |
35 | funktion(); | 100 | indentation for preprocessor directives |
36 | 101 | ||
37 | The include guards: | 102 | They should always have a // PREPROCESSOR to mark where they end |
38 | FILENAME_HH | 103 | #ifdef DEBUG |
104 | ... | ||
105 | ... | ||
106 | #endif //DEBUG | ||
39 | 107 | ||
108 | Don't use preprocessors for constants or macro-functions, they can be | ||
109 | cryptic and sometime make it hard to debug. | ||
110 | |||
111 | |||
112 | functions: | ||
113 | The name starts with a lowercase and then a uppercase for name separation: | ||
114 | void functionWithAName(...) { | ||
115 | ...; | ||
116 | } | ||
40 | 117 | ||
41 | Function comments: | 118 | Function comments: |
42 | //------------ function name -------- | ||
43 | // This do that and that | 119 | // This do that and that |
44 | // Returns this on success else | 120 | // Returns this on success else |
45 | // this on failure. | 121 | // this on failure. |
46 | // TODO: if there is something to do. | 122 | // TODO: if there is something to do. |
47 | //----------------------------------- | 123 | void functionDoes(...) { |
48 | type classname::function(...) { | 124 | |
125 | } | ||
126 | Comments: | ||
127 | Use // on few line comments. | ||
128 | Use | ||
129 | /* | ||
130 | ... | ||
131 | ... | ||
132 | */ | ||
133 | when there are a lot to comment | ||
134 | |||
135 | Class: | ||
136 | Order: public, protected and then private | ||
137 | Class names always starts with a big letter. | ||
138 | Class data members are prefixed by m_ , static data members are prefixed with s_ . | ||
139 | Class member function will be organized according to creator, | ||
140 | manipulator and accessors categories. | ||
141 | |||
142 | class Classname:public AnotherClass { | ||
143 | public: | ||
144 | //1. public enums, structs | ||
145 | |||
146 | //2. constructors and destructor | ||
147 | |||
148 | //3. manipulators | ||
149 | |||
150 | //4. accessors | ||
151 | |||
152 | protected: | ||
153 | //1. enums, structs | ||
154 | |||
155 | //2. functions | ||
156 | |||
157 | //3. variables | ||
158 | |||
159 | private: | ||
160 | //1. enums, structs | ||
161 | |||
162 | //2. functions | ||
163 | |||
164 | //3. variables | ||
165 | }; | ||
166 | |||
167 | |||
168 | struct follows the class style. | ||
169 | |||
170 | namespace: | ||
171 | namespace TheName { | ||
172 | ...; | ||
173 | ...; | ||
174 | }; //end namespace TheName | ||
175 | |||
176 | Don't use "using namespace thenamespace;" in header-file | ||
177 | We don't want to force the other files, that include the file, a namespace. | ||
178 | |||
49 | 179 | ||
180 | try/catch-statement: | ||
181 | |||
182 | try { | ||
183 | ....; | ||
184 | } catch (...) { | ||
185 | ....; | ||
50 | } | 186 | } |
51 | 187 | ||
188 | Variables: | ||
189 | Avoid variables that contain mixtures of the numbers 0 & l and the letters O | ||
190 | and 1, because they are hard to tell apart. | ||
191 | Having a type name and a variable differing in only in case (such as: | ||
192 | String string;) is permitted, but discouraged. | ||
193 | |||
194 | Use lowercase for variables and use _ to separate names, ex: | ||
195 | int number_of_screens; | ||
196 | int num_colors; | ||
197 | |||
198 | |||
199 | All constants must be in Upper case letters. | ||
52 | 200 | ||
53 | enums must be in uppercase letters and not in file scope: | 201 | enums must be in uppercase letters and not in file scope: |
54 | enum {WHITE, RED, BLUE}; | 202 | enum {WHITE, RED, BLUE}; |
55 | 203 | ||
56 | Class data members are prefixed by m_ | 204 | Other: |
57 | Class member function will be organized accordning to creator, | 205 | |
58 | manipulator and accessor categories. | 206 | if (strcmp(...) == 0) //good |
207 | if (!strcmp()) //bad | ||
208 | |||
209 | Don't create free-functions, encapsulate them in a namespace or a class | ||
210 | and name filenames so it's clear what they hold so it's easier to find | ||
211 | functions, classes and other stuff. | ||
212 | |||