diff options
Diffstat (limited to 'doc/developer-notes.md')
-rw-r--r-- | doc/developer-notes.md | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/doc/developer-notes.md b/doc/developer-notes.md index ba03579e86..797507cd3e 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -4,16 +4,21 @@ Developer Notes 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. +gradually and you are encouraged to use the provided +[clang-format-diff script](/contrib/devtools/README.md#clang-format-diffpy) +to clean up the patch automatically before submitting a pull request. + - Basic rules specified in [src/.clang-format](/src/.clang-format). - Use a recent clang-format to format automatically using one of the [dev scripts] - (/contrib/devtools/README.md#clang-formatpy). - 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 indentation for `public`/`protected`/`private` or for `namespace`. - No extra spaces inside parenthesis; don't do ( this ) - - No space after function names; one space after if, for and while. + - No space after function names; one space after `if`, `for` and `while`. + - If an `if` only has a single-statement then-clause, it can appear + on the same line as the if, without braces. In every other case, + braces are required, and the then and else clauses must appear + correctly indented on a new line. - `++i` is preferred over `i++`. Block style example: @@ -22,14 +27,18 @@ namespace foo { class Class { - bool Function(char* psz, int n) + bool Function(const std::string& s, 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; + if (!Something()) return false; ... + if (SomethingElse()) { + DoMore(); + } else { + DoLess(); + } } // Success return is usually at the end @@ -123,7 +132,7 @@ Run with the -testnet option to run with "play bitcoins" on the test network, if are testing multi-machine code that needs to operate across the internet. If you are testing something that can run on one machine, run with the -regtest option. -In regression test mode, blocks can be created on-demand; see qa/rpc-tests/ for tests +In regression test mode, blocks can be created on-demand; see test/functional/ for tests that run in -regtest mode. **DEBUG_LOCKORDER** @@ -243,7 +252,7 @@ Wallet - *Rationale*: In RPC code that conditionally uses the wallet (such as `validateaddress`) it is easy to forget that global pointer `pwalletMain` - can be NULL. See `qa/rpc-tests/disablewallet.py` for functional tests + can be NULL. See `test/functional/disablewallet.py` for functional tests exercising the API with `-disablewallet` - Include `db_cxx.h` (BerkeleyDB header) only when `ENABLE_WALLET` is set @@ -439,7 +448,7 @@ Current subtrees include: - Upstream at https://github.com/jgarzik/univalue ; report important PRs to Core to avoid delay. -Git and github tips +Git and GitHub tips --------------------- - For resolving merge/rebase conflicts, it can be useful to enable diff3 style using |