You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bestpractices/c++practices.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,11 @@ and other code.
14
14
Some code might only make sense in a given context, but if the functionality
15
15
is generic, it could be put in a library or suchlike.
16
16
17
-
Use a (named) namespace to house free functions rather than a class or struct
18
-
full of static (or what should be static) functions.
19
-
In addition, private static functions doesn't even need to be declared in the header file.
17
+
Use a *named namespace* to house free functions rather than relying on a class or struct filled with static functions (or functions that should be static).
18
+
This approach ensures better organization and clarity.
19
+
20
+
In addition, private static functions do not need to be declared in the header file when moved out of a class.
21
+
This reduces unnecessary exposure of implementation details.
20
22
21
23
## Algorithms and data structures
22
24
@@ -199,10 +201,10 @@ This provides compile-time evaluation. Can increase compile time, but speedup ru
199
201
200
202
Hard dependencies makes the codebase more entangled, makes changes more difficult, and makes unit testing really difficult.
201
203
202
-
Examples of dependencies creeping in:
204
+
Three examples of dependencies creeping in:
203
205
```cpp
204
206
Application::getSomething(); // or any other singleton
205
-
SomeDistantClass fing;
207
+
SomeDistantClass thing;
206
208
voidmethod(AnotherDistantClass values){}
207
209
```
208
210
@@ -341,9 +343,9 @@ doThing();
341
343
342
344
## Initialization
343
345
344
-
**Initialize all objects, and, if possible, make const or better still, constexpr.**
346
+
**Initialize all objects, and, if possible, use const or better still, constexpr.**
345
347
346
-
Avoid default constructors. If there is not yet a value for an object, then there's no need to create it. Declare variables close to where they are used (there's no need to start the declear variables at the start of the block like in ansi-c). Joining declaration and initialization allows const:
348
+
Avoid default constructors. If there is not yet a value for an object, then there's no need to create it. Declare variables close to where they are used (there's no need to start the declare variables at the start of the block like in ansi-c). Joining declaration and initialization allows const:
347
349
348
350
```cpp
349
351
AType thing; // mutable. Does it have a default constructor?
@@ -475,7 +477,7 @@ For an object that _is_ something (value object), prefer a noun. E.g. `drawing`.
475
477
476
478
Something difficult to name concisely likely does not have a single purpose and needs refactoring.
477
479
478
-
Use names that are specific. E.g. `SaveLogToDisc`, not `ProcessLog`. "Process" could be anything.
480
+
Use names that are specific. E.g. `SaveLogToDisk`, not `ProcessLog`. `Process` could be anything.
479
481
480
482
A variable named after its data value defeats the whole point of a variable:
481
483
```cpp
@@ -551,7 +553,7 @@ Writing tests on a coupled design is difficult, therefore removing hard dependen
551
553
552
554
Test driven development, where tests are written before, and during code creation, is a good practice to follow to ensure good quality code. Writing tests afterwards can be difficult as it won't help you with code design as much when code is produced.
553
555
554
-
Gui is often classified as untestable as there's few good tools to verify behavior when buttons and sliders are manipulated. And while gui can't easily be tested, the logic it is connected to, can. Splitting ui from from "business logic" is a good choice and highly recommended.
556
+
Gui code is often classified as untestable because there are good tools to verify behavior when buttons and sliders are manipulated. And while gui code can't easily be tested, the logic it is connected to, can. Splitting ui from from "business logic" is a good choice and highly recommended.
555
557
556
558
Just like good naming is important for variables and functions, naming tests are too. A good test name describes what has been tested. This way, when it fails for someone else, they can easily see what failed.
Copy file name to clipboardExpand all lines: bestpractices/codereview.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,9 +27,10 @@ In this document the **bolded** text will indicate how important each suggestion
27
27
5. Comments **could** be made to existing comments just to note that other (potentially better) soluyions are available and should be used instead when writing new code.
28
28
6. Reviewer **can** hint to make more changes to the existing code in order to improve the proposed solution (for example, refactor another class so it can be used).
29
29
7. Code **must** follow the Scout Rule - https://biratkirat.medium.com/step-8-the-boy-scout-rule-robert-c-martin-uncle-bob-9ac839778385 - i.e. leave code in better shape than you found it.
30
-
8. PRs **must not** contain any remains of development code, like debug statements other than actual logs.
31
-
9. New code **must not** introduce any new linter warnings
32
-
10. Developer **should** have `pre-commit` installed and working. `pre-commit-ci` commits should be avoided.
30
+
8. If possible, code cleanup done while working on the feature should be split into separate commits or even better PR.
31
+
9. PRs **must not** contain any remains of development code, like debug statements other than actual logs.
32
+
10. New code **must not** introduce any new linter warnings
33
+
11. Developer **should** have `pre-commit` installed and working. `pre-commit-ci` commits should be avoided.
33
34
34
35
## Basic Code Rules
35
36
1. (C++ only) New code **must** be formatted with clang-format tool or in a way that is compatible with clang-format result if file is excluded from auto formatting.
0 commit comments