forked from grnet/archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CODINGSTYLE
122 lines (99 loc) · 2.22 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
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
# Archipelago Coding Style
This is a coding style guide for Archipelago.
## 1. Indentation and layout
1.1 Use 4 spaces for indentation, no tabs.
1.2 Put the case in switch statements on the same indentation
```
switch(op) {
case 1:
break;
case 2:
case 3:
break;
default:
break;
}
```
1.3 Do not use multiple statements on the same line:
```
m++; n++;
```
1.4 Line length should not exceed 80 characters.
## 2. Spaces
2.1 Use spaces around binary and ternary operators.
```
n = n + 8;
if (j == 8 || i < 9) {
n += 8;
n = 8 + 9 * 10;
n = j < 1 ? j : 0;
```
2.2 Do not use spaces around unary operators.
```
n -= 2;
j = *p;
for (n = 0; n < 10; n++) {
```
2.3 Do not use spaces between a function and its parameters, or
a template and its parameters.
```
abs(-2.0)
std::vector<kernel*>
```
2.4 Bind '&' to the type and not the variable
```
int& k;
```
The rule does not apply when multiple variables are declared on the same line.
In such cases, it is preferable to do:
...
int &k, &l;
...
2.5 Bind '*' to the variable and not the type
```
int *k;
int *k, *l;
```
## 3. Braces
3.1 Use curly braces for the 'if' statement even if it is only a line.
3.2 Use single-space when a brace-delimited block is part of a statement.
```
if (n == 8) {
...
}
```
3.3 In inline methods use the open braces at the same line of the method.
```
int use_scope() {
...
}
```
3.4 In longer methods the opening brace should be at the beginning of the
line.
```
void abs()
{
...
}
```
## 4. Commenting
4.1 Use the // C++ comment style for normal comments
4.2 Use /* */ comments for namespaces, classes, method or functions.
## 5. Macros and Enums
5.1 Avoid macros when a method or function would do. Prefer enum and constant
to macro.
5.2 Prefer "enum class" to "enum" (C++)
5.3 Capitalize macro names and enum labels. For "enum class", non-capitalized
values are fine.
## 6. Functions
6.1 Put no space between function name and the argument list.
```
double sqrt(double d)
{
```
6.2 Avoid parentheses around return value
```
return 0;
return i + j
```
"return" is not a function call, parentheses are not required.