@@ -141,6 +141,27 @@ public:
141
141
} // namespace foo
142
142
```
143
143
144
+ Coding Style (C++ functions and methods)
145
+ --------------------
146
+
147
+ - When ordering function parameters, place input parameters first, then any
148
+ in-out parameters, followed by any output parameters.
149
+
150
+ - * Rationale* : API consistency.
151
+
152
+ - Prefer returning values directly to using in-out or output parameters. Use
153
+ ` std::optional ` where helpful for returning values.
154
+
155
+ - * Rationale* : Less error-prone (no need for assumptions about what the output
156
+ is initialized to on failure), easier to read, and often the same or better
157
+ performance.
158
+
159
+ - Generally, use ` std::optional ` to represent optional by-value inputs (and
160
+ instead of a magic default value, if there is no real default). Non-optional
161
+ input parameters should usually be values or const references, while
162
+ non-optional in-out and output parameters should usually be references, as
163
+ they cannot be null.
164
+
144
165
Coding Style (C++ named arguments)
145
166
------------------------------
146
167
@@ -1390,22 +1411,9 @@ communication:
1390
1411
virtual boost::signals2::scoped_connection connectTipChanged(TipChangedFn fn) = 0;
1391
1412
```
1392
1413
1393
- - For consistency and friendliness to code generation tools, interface method
1394
- input and in-out parameters should be ordered first and output parameters
1395
- should come last.
1414
+ - Interface methods should not be overloaded.
1396
1415
1397
- Example:
1398
-
1399
- ```c++
1400
- // Good: error output param is last
1401
- virtual bool broadcastTransaction(const CTransactionRef& tx, CAmount max_fee, std::string& error) = 0;
1402
-
1403
- // Bad: error output param is between input params
1404
- virtual bool broadcastTransaction(const CTransactionRef& tx, std::string& error, CAmount max_fee) = 0;
1405
- ```
1406
-
1407
- - For friendliness to code generation tools, interface methods should not be
1408
- overloaded:
1416
+ *Rationale*: consistency and friendliness to code generation tools.
1409
1417
1410
1418
Example:
1411
1419
@@ -1421,10 +1429,11 @@ communication:
1421
1429
1422
1430
### Internal interface naming style
1423
1431
1424
- - For consistency and friendliness to code generation tools, interface method
1425
- names should be `lowerCamelCase` and standalone function names should be
1432
+ - Interface method names should be ` lowerCamelCase ` and standalone function names should be
1426
1433
` UpperCamelCase ` .
1427
1434
1435
+ * Rationale* : consistency and friendliness to code generation tools.
1436
+
1428
1437
Examples:
1429
1438
1430
1439
``` c++
0 commit comments