Skip to content

Commit 55b72f3

Browse files
committed
Merge #10461: Update style guide
47d8441 Update style guide (Pieter Wuille) Tree-SHA512: 0b11365f294eeda1ea5c45cf04b3f38435602f61edc0c605e067ed9d17d17c28e9f1dd76bd4fa8a630e9cec8c5103cd2bfe5f6097196761d576913d9180f2ecf
2 parents c1c9a95 + 47d8441 commit 55b72f3

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

doc/developer-notes.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,64 @@ Developer Notes
33

44
Various coding styles have been used during the history of the codebase,
55
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.
1011

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.
1216
- Braces on new lines for namespaces, classes, functions, methods.
1317
- Braces on the same line for everything else.
1418
- 4 space indentation (no tabs) for every block except namespaces.
1519
- No indentation for `public`/`protected`/`private` or for `namespace`.
1620
- No extra spaces inside parenthesis; don't do ( this )
1721
- 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
2125
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**
2239
- `++i` is preferred over `i++`.
2340

2441
Block style example:
2542
```c++
43+
int g_count = 0;
44+
2645
namespace foo
2746
{
2847
class Class
2948
{
49+
std::string m_name;
50+
51+
public:
3052
bool Function(const std::string& s, int n)
3153
{
3254
// Comment summarising what this section of code does
3355
for (int i = 0; i < n; ++i) {
56+
int total_sum = 0;
3457
// When something fails, return early
3558
if (!Something()) return false;
3659
...
37-
if (SomethingElse()) {
38-
DoMore();
60+
if (SomethingElse(i)) {
61+
total_sum += ComputeSomething(g_count);
3962
} else {
40-
DoLess();
63+
DoSomething(m_name, total_sum);
4164
}
4265
}
4366

0 commit comments

Comments
 (0)