]> Git Repo - VerusCoin.git/blame - doc/coding.md
ensure clean and consistent "namespace" usage
[VerusCoin.git] / doc / coding.md
CommitLineData
2341e9b5 1Coding
2====================
3
4Please be consistent with the existing coding style.
5
6Block 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
23- ANSI/Allman block style
24- 4 space indenting, no tabs
25- No extra spaces inside parenthesis; please don't do ( this )
26- No space after function names, one space after if, for and while
27
28Variable names begin with the type in lowercase, like nSomeVariable.
29Please don't put the first word of the variable name in lowercase like
30someVariable.
31
32Common types:
33
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
45
8414cb04
WL
46Doxygen comments
47-----------------
48
49To facilitate the generation of documentation, use doxygen-compatible comment blocks for functions, methods and fields.
50
51For example, to describe a function use:
52```c++
53/**
54 * ... text ...
55 * @param[in] arg1 A description
56 * @param[in] arg2 Another argument description
57 * @pre Precondition for function...
58 */
59bool function(int arg1, const char *arg2)
60```
61A complete list of `@xxx` commands can be found at http://www.stack.nl/~dimitri/doxygen/manual/commands.html.
62As Doxygen recognizes the comments by the delimiters (`/**` and `*/` in this case), you don't
63*need* to provide any commands for a comment to be valid, just a description text is fine.
64
65To describe a class use the same construct above the class definition:
66```c++
67/**
68 * Alerts are for notifying old versions if they become too obsolete and
69 * need to upgrade. The message is displayed in the status bar.
70 * @see GetWarnings()
71 */
72class CAlert
73{
74```
75
76To describe a member or variable use:
77```c++
78int var; //!< Detailed description after the member
79```
80
81Also OK:
82```c++
83///
84/// ... text ...
85///
86bool function2(int arg1, const char *arg2)
87```
88
89Not OK (used plenty in the current source, but not picked up):
90```c++
91//
92// ... text ...
93//
94```
95
96A full list of comment syntaxes picked up by doxygen can be found at http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html,
97but if possible use one of the above styles.
98
2341e9b5 99Locking/mutex usage notes
8414cb04 100-------------------------
2341e9b5 101
102The code is multi-threaded, and uses mutexes and the
103LOCK/TRY_LOCK macros to protect data structures.
104
105Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
106and then cs_wallet, while thread 2 locks them in the opposite order:
107result, deadlock as each waits for the other to release its lock) are
108a problem. Compile with -DDEBUG_LOCKORDER to get lock order
109inconsistencies reported in the debug.log file.
110
111Re-architecting the core code so there are better-defined interfaces
112between the various components is a goal, with any necessary locking
113done by the components (e.g. see the self-contained CKeyStore class
114and its cs_KeyStore lock for example).
115
2341e9b5 116Threads
8414cb04 117-------
2341e9b5 118
25ef6ace 119- ThreadScriptCheck : Verifies block scripts.
120
121- ThreadImport : Loads blocks from blk*.dat files or bootstrap.dat.
122
2341e9b5 123- StartNode : Starts other threads.
124
25ef6ace 125- ThreadGetMyExternalIP : Determines outside-the-firewall IP address, sends addr message to connected peers when it determines it.
126
127- ThreadDNSAddressSeed : Loads addresses of peers from the DNS.
128
129- ThreadMapPort : Universal plug-and-play startup/shutdown
2341e9b5 130
131- ThreadSocketHandler : Sends/Receives data from peers on port 8333.
25ef6ace 132
133- ThreadOpenAddedConnections : Opens network connections to added nodes.
134
2341e9b5 135- ThreadOpenConnections : Initiates new connections to peers.
136
25ef6ace 137- ThreadMessageHandler : Higher-level message handling (sending and receiving).
138
139- DumpAddresses : Dumps IP addresses of nodes to peers.dat.
2341e9b5 140
141- ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms.
25ef6ace 142
2341e9b5 143- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them.
25ef6ace 144
145- BitcoinMiner : Generates bitcoins (if wallet is enabled).
146
147- Shutdown : Does an orderly shutdown of everything.
This page took 0.066992 seconds and 4 git commands to generate.