|
4 | 4 | Please be consistent with the existing coding style. |
5 | 5 |
|
6 | 6 | Block style: |
7 | | - |
8 | | - bool Function(char* psz, int n) |
9 | | - { |
10 | | - // Comment summarising what this section of code does |
11 | | - for (int i = 0; i < n; i++) |
12 | | - { |
13 | | - // When something fails, return early |
14 | | - if (!Something()) |
15 | | - return false; |
16 | | - ... |
17 | | - } |
18 | | - |
19 | | - // Success return is usually at the end |
20 | | - return true; |
21 | | - } |
22 | | - |
| 7 | +```c++ |
| 8 | + bool Function(char* psz, int n) |
| 9 | + { |
| 10 | + // Comment summarising what this section of code does |
| 11 | + for (int i = 0; i < n; i++) |
| 12 | + { |
| 13 | + // When something fails, return early |
| 14 | + if (!Something()) |
| 15 | + return false; |
| 16 | + ... |
| 17 | + } |
| 18 | + |
| 19 | + // Success return is usually at the end |
| 20 | + return true; |
| 21 | + } |
| 22 | +``` |
23 | 23 | - ANSI/Allman block style |
24 | 24 | - 4 space indenting, no tabs |
25 | 25 | - No extra spaces inside parenthesis; please don't do ( this ) |
26 | 26 | - No space after function names, one space after if, for and while |
| 27 | +- Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp): |
| 28 | +```c++ |
| 29 | +#include "key.h" |
| 30 | +
|
| 31 | +#include "crypto/sha2.h" |
| 32 | +#include "util.h" |
27 | 33 |
|
| 34 | +#include <openssl/foo.h> |
| 35 | +``` |
| 36 | +- Class or struct keywords in header files need to be ordered alphabetically: |
| 37 | +```c++ |
| 38 | +class CAlpha; |
| 39 | +class CBeta; |
| 40 | +``` |
| 41 | +- When using namespace keyword use the following form: |
| 42 | +```c++ |
| 43 | +namespace Foo { |
| 44 | + |
| 45 | +... |
| 46 | + |
| 47 | +} // Foo |
| 48 | +``` |
28 | 49 | Variable names begin with the type in lowercase, like nSomeVariable. |
29 | 50 | Please don't put the first word of the variable name in lowercase like |
30 | 51 | someVariable. |
31 | 52 |
|
32 | 53 | Common types: |
33 | 54 |
|
34 | | - n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number |
35 | | - d double, float |
36 | | - f flag |
37 | | - hash uint256 |
38 | | - p pointer or array, one p for each level of indirection |
39 | | - psz pointer to null terminated string |
40 | | - str string object |
41 | | - v vector or similar list objects |
42 | | - map map or multimap |
43 | | - set set or multiset |
44 | | - bn CBigNum |
| 55 | + n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number |
| 56 | + d double, float |
| 57 | + f flag |
| 58 | + hash uint256 |
| 59 | + p pointer or array, one p for each level of indirection |
| 60 | + psz pointer to null terminated string |
| 61 | + str string object |
| 62 | + v vector or similar list objects |
| 63 | + map map or multimap |
| 64 | + set set or multiset |
| 65 | + bn CBigNum |
45 | 66 |
|
46 | 67 | Doxygen comments |
47 | 68 | ----------------- |
|
0 commit comments