@@ -3,41 +3,64 @@ Developer Notes
3
3
4
4
Various coding styles have been used during the history of the codebase,
5
5
and the result is not very consistent. However, we're now trying to converge to
6
- a single style, so please use it in new code. Old code will be converted
7
- gradually and you are encouraged to use the provided
8
- [ clang-format-diff script] ( /contrib/devtools/README.md#clang-format-diffpy )
9
- to clean up the patch automatically before submitting a pull request.
6
+ a single style, which is specified below. When writing patches, favor the new
7
+ style over attempting to mimick the surrounding style, except for move-only
8
+ commits.
9
+
10
+ Do not submit patches solely to modify the style of existing code.
10
11
11
- - Basic rules specified in [ src/.clang-format] ( /src/.clang-format ) .
12
+ - ** Indentation and whitespace rules** as specified in
13
+ [ src/.clang-format] ( /src/.clang-format ) . You can use the provided
14
+ [ clang-format-diff script] ( /contrib/devtools/README.md#clang-format-diffpy )
15
+ tool to clean up patches automatically before submission.
12
16
- Braces on new lines for namespaces, classes, functions, methods.
13
17
- Braces on the same line for everything else.
14
18
- 4 space indentation (no tabs) for every block except namespaces.
15
19
- No indentation for ` public ` /` protected ` /` private ` or for ` namespace ` .
16
20
- No extra spaces inside parenthesis; don't do ( this )
17
21
- No space after function names; one space after ` if ` , ` for ` and ` while ` .
18
- - If an ` if ` only has a single-statement then-clause, it can appear
19
- on the same line as the if , without braces. In every other case,
20
- braces are required, and the then and else clauses must appear
22
+ - If an ` if ` only has a single-statement ` then ` -clause, it can appear
23
+ on the same line as the ` if ` , without braces. In every other case,
24
+ braces are required, and the ` then ` and ` else ` clauses must appear
21
25
correctly indented on a new line.
26
+
27
+ - ** Symbol naming conventions** . These are preferred in new code, but are not
28
+ required when doing so would need changes to significant pieces of existing
29
+ code.
30
+ - Variable and namespace names are all lowercase, and may use ` _ ` to
31
+ separate words.
32
+ - Class member variables have a ` m_ ` prefix.
33
+ - Global variables have a ` g_ ` prefix.
34
+ - Constant names are all uppercase, and use ` _ ` to separate words.
35
+ - Class names, function names and method names are CamelCase. Do not prefix
36
+ class names with ` C ` .
37
+
38
+ - ** Miscellaneous**
22
39
- ` ++i ` is preferred over ` i++ ` .
23
40
24
41
Block style example:
25
42
``` c++
43
+ int g_count = 0 ;
44
+
26
45
namespace foo
27
46
{
28
47
class Class
29
48
{
49
+ std::string m_name;
50
+
51
+ public:
30
52
bool Function(const std::string& s, int n)
31
53
{
32
54
// Comment summarising what this section of code does
33
55
for (int i = 0; i < n; ++i) {
56
+ int total_sum = 0;
34
57
// When something fails, return early
35
58
if (!Something()) return false;
36
59
...
37
- if (SomethingElse()) {
38
- DoMore ( );
60
+ if (SomethingElse(i )) {
61
+ total_sum += ComputeSomething(g_count );
39
62
} else {
40
- DoLess( );
63
+ DoSomething(m_name, total_sum );
41
64
}
42
65
}
43
66
0 commit comments