all repos — fluxbox @ edafa987bee64b898ab301263431f97fbd9445e2

custom fork of the fluxbox windowmanager

doc/Coding_style (raw)

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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Use 4 space indent
Spaces between ","
ex:  1, 2, a, 4

if/else-statements:
An else clause is joined to any preceding close curly brace
that is part of its if.

if (....) {
    ....
} else {
    ....
}
if the line needs to be splited up, right after an if-statement
use { and }, so its clear when the if-statement ends.
ex: 
if (...) {
    function(.....,
             ......, .... );
}

This is ok:
if (...)
    shortline(...);


while-statement:

while (...) {
    ....
}

for-statement:

for (init; condition; update) {
    ....
}

for (longinit;
     longcondition;
     longupdate ) {
    ....
}
alt form:

init;
for (; condition; update) {
    ....
}

do-statement:

do {
    ....
} while (...);

switch-statement:
should always have a default value.
Enum values is an exception, they should not have a default: , when you add 
new values to an enum you might forget to add them to switch statement.

switch (...) {
    case ...:
        ...;
        break;
    case ...: {
        ...;
    } break;
    case ...:
        ...;
    default:
        ....;
       break;
}

Include guards:
For files with namespace:
#ifndef NAMESPACE_FILENAME_HH
#define NAMESPACE_FILENAME_HH
....

#endif //NAMESPACE_FILENAME_HH 
<eof>

Without namespace:
#ifndef FILENAME_HH
#define FILENAME_HH
....

#endif //FILENAME_HH

<eof>

preprocessors:
The # of all preprocessor commands must always be in column 1, and never use 
indentation for preprocessor directives

They should always have a // PREPROCESSOR to mark where they end
#ifdef DEBUG
...
...
#endif //DEBUG

Don't use preprocessors for constants or macro-functions, they can be 
cryptic and sometime make it hard to debug.


functions:
The name starts with a lowercase and then a uppercase for name separation:
void functionWithAName(...) {
    ...;
}

Use Javadoc style for function description (see www.doxygen.org)
Function comments:
/**
 This do that and that
 @return this on success else this on failure.
 TODO: if there is something to do.
*/
void functionDoes(...) {

}

Class:
Order: public, protected and then private
Class names always starts with a big letter.
Class data members are prefixed by m_ , static data members are prefixed with s_ .
Class member function will be organized according to creator, 
manipulator and accessors categories.

class Classname:public AnotherClass {
public:
    //1. public enums, structs
    
    //2. constructors and destructor
    
    //3. manipulators
    
    //4. accessors
    
protected:
    //1. enums, structs
    
    //2. functions
    
    //3. variables

private:
    //1. enums, structs
    
    //2. functions
    
    //3. variables
};


struct follows the class style.

namespace:
namespace TheName {
...;
...;
}; //end namespace TheName

Don't use "using namespace thenamespace;" in header-file
We don't want to force the other files, that include the file, a namespace.


try/catch-statement:

try {
    ....;
} catch (...) {
    ....;
}

Variables:
Avoid variables that contain mixtures of the numbers 0 & l and the letters O 
and 1, because they are hard to tell apart.
Having a type name and a variable differing in only in case (such as:
 String string;) is permitted, but discouraged.

Use lowercase for variables and use _ to separate names, ex:
int number_of_screens;
int num_colors;


All constants must be in Upper case letters.

enums must be in uppercase letters and not in file scope:
enum {WHITE, RED, BLUE};

Other:

if (strcmp(...) == 0) //good
if (!strcmp()) //bad

Don't create free-functions, encapsulate them in a namespace or a class
and name filenames so it's clear what they hold so it's easier to find
functions, classes and other stuff.


ChangeLog format:
*year/month/day:
   * whats changed (who changed it)
     which file

ex:

*02/01/01:
   * Fixed bug workspace change (TheDude)
     Workspace.cc