Skip to content

Commit c81acdb

Browse files
hyarionkadet1090
authored andcommitted
Fix best practices based on @pieterhijma's review
1 parent b29e281 commit c81acdb

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

bestpractices/c++practices.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ and other code.
1414
Some code might only make sense in a given context, but if the functionality
1515
is generic, it could be put in a library or suchlike.
1616

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.
2022

2123
## Algorithms and data structures
2224

@@ -199,10 +201,10 @@ This provides compile-time evaluation. Can increase compile time, but speedup ru
199201

200202
Hard dependencies makes the codebase more entangled, makes changes more difficult, and makes unit testing really difficult.
201203

202-
Examples of dependencies creeping in:
204+
Three examples of dependencies creeping in:
203205
```cpp
204206
Application::getSomething(); // or any other singleton
205-
SomeDistantClass fing;
207+
SomeDistantClass thing;
206208
void method(AnotherDistantClass values){}
207209
```
208210
@@ -341,9 +343,9 @@ doThing();
341343

342344
## Initialization
343345

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.**
345347

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:
347349

348350
```cpp
349351
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`.
475477

476478
Something difficult to name concisely likely does not have a single purpose and needs refactoring.
477479

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.
479481

480482
A variable named after its data value defeats the whole point of a variable:
481483
```cpp
@@ -551,7 +553,7 @@ Writing tests on a coupled design is difficult, therefore removing hard dependen
551553
552554
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.
553555

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.
555557
556558
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.
557559

bestpractices/codereview.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ In this document the **bolded** text will indicate how important each suggestion
2727
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.
2828
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).
2929
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.
3334

3435
## Basic Code Rules
3536
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

Comments
 (0)