diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-08-06 17:17:15 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-08-06 17:17:32 +0200 |
commit | 8833acc4c979877993f87c8fdc8a6d14cd072ba2 (patch) | |
tree | 4b9f7c0f802da91161ed749336603ddb1c861368 /doc | |
parent | e05d72055aee7937fc6e0cda8a25f4bde88a2a13 (diff) | |
parent | 2887bffcfdc138f53c60091ab2906790971c9af5 (diff) |
Merge pull request #4498
2887bff Update coding style and add .clang-format (Pieter Wuille)
Diffstat (limited to 'doc')
-rw-r--r-- | doc/coding.md | 76 |
1 files changed, 31 insertions, 45 deletions
diff --git a/doc/coding.md b/doc/coding.md index 2f332e92f0..ceed8c18b4 100644 --- a/doc/coding.md +++ b/doc/coding.md @@ -1,29 +1,17 @@ Coding ==================== -Please be consistent with the existing coding style. - -Block style: -```c++ - bool Function(char* psz, int n) - { - // Comment summarising what this section of code does - for (int i = 0; i < n; i++) - { - // When something fails, return early - if (!Something()) - return false; - ... - } - - // Success return is usually at the end - return true; - } -``` -- ANSI/Allman block style -- 4 space indenting, no tabs -- No extra spaces inside parenthesis; please don't do ( this ) -- No space after function names, one space after if, for and while +Various coding styles have been used during the history of the codebase, +and the result is not very consistent. However, we're now trying to converge to +a single style, so please use it in new code. Old code will be converted +gradually. +- Basic rules specified in src/.clang-format. Use a recent clang-format-3.5 to format automatically. + - Braces on new lines for namespaces, classes, functions, methods. + - Braces on the same line for everything else. + - 4 space indentation (no tabs) for every block except namespaces. + - No indentation for public/protected/private or for namespaces. + - No extra spaces inside parenthesis; don't do ( this ) + - No space after function names; one space after if, for and while. - Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp): ```c++ #include "key.h" @@ -38,31 +26,29 @@ Block style: class CAlpha; class CBeta; ``` -- When using namespace keyword use the following form: -```c++ -namespace Foo { -... +Block style example: +```c++ +namespace foo +{ +class Class +{ + bool Function(char* psz, int n) + { + // Comment summarising what this section of code does + for (int i = 0; i < n; i++) { + // When something fails, return early + if (!Something()) + return false; + ... + } -} // Foo + // Success return is usually at the end + return true; + } +} +} ``` -Variable names begin with the type in lowercase, like nSomeVariable. -Please don't put the first word of the variable name in lowercase like -someVariable. - -Common types: - - n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number - d double, float - f flag - hash uint256 - p pointer or array, one p for each level of indirection - psz pointer to null terminated string - str string object - v vector or similar list objects - map map or multimap - set set or multiset - bn CBigNum Doxygen comments ----------------- |