-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodingStyle
87 lines (60 loc) · 1.64 KB
/
CodingStyle
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
Coding Style
============
As a general rule :-
- all indentation is tabs (set to 8 char) with the exception of
continuation lines that are aligned with tabs and then spaces
- all keywords followed by a '(' have a space in between
if (condition)
for (i = 0; i < 5; i++)
- function calls do NOT have a space between their name and argument
i = some_function(argument);
- usually there is no space on the inside of parenthesis (see examples
above)
- function / method implementations have their opening curly braces in
column 1
- all other opening curly braces follow at the end of the line, with a
space separating them:
if (condition) {
dosomething();
dosomethingelse();
}
- both sides of an if / else clause either use or do not use curly braces:
if (condition)
i = 4;
else
j = 6;
if (condition) {
i = 6;
} else {
i = 4;
j = 6;
}
- don't do assignments inside if () statements, always do it this way
res = something();
if (!res)
return NULL;
- if you don't need the result you can do
if (!something())
return NULL;
- use space to make visual separation easier
a = b + 3 + e / 4;
- continuation lines have the operator / comma at the end
if (very_long_conditiont_1 ||
condition_2)
b = a + (c + d +
f + z);
- switch statements with blocks are a little bit special (to avoid indenting
too far)
switch (foo) {
case FIRST:
whatever();
break;
case SECOND: {
int i;
for (i = 0; i < 5; i++)
do_something(i);
}
}
- variable declarations should be at the beginning of a code block, not
interspersed in the middle
- variable and function naming should be all lower case with _ used for spaces