Skip to content

Commit 359bac7

Browse files
paveljaniklaanwj
authored andcommitted
Add notes about variable names and shadowing
1 parent fd5654c commit 359bac7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

doc/developer-notes.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,32 @@ Strings and formatting
331331

332332
- *Rationale*: Bitcoin Core uses tinyformat, which is type safe. Leave them out to avoid confusion
333333

334+
Variable names
335+
--------------
336+
337+
The shadowing warning (`-Wshadow`) is enabled by default. It prevents issues rising
338+
from using a different variable with the same name.
339+
340+
Please name variables so that their names do not shadow variables defined in the source code.
341+
342+
E.g. in member initializers, prepend `_` to the argument name shadowing the
343+
member name:
344+
345+
```c++
346+
class AddressBookPage
347+
{
348+
Mode mode;
349+
}
350+
351+
AddressBookPage::AddressBookPage(Mode _mode) :
352+
mode(_mode)
353+
...
354+
```
355+
356+
When using nested cycles, do not name the inner cycle variable the same as in
357+
upper cycle etc.
358+
359+
334360
Threads and synchronization
335361
----------------------------
336362

0 commit comments

Comments
 (0)