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
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ layout: default
4
4
5
5
# C++ practices
6
6
7
-
Most rules presented here cover the same things as the very good [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
7
+
Most rules presented here cover the same things as the very good [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
8
8
Whenever something is not covered or you are in doubt - don't hesitate to consult it - it is a very good source of information.
9
9
10
10
## Avoid anonymous namespaces
@@ -31,7 +31,7 @@ In addition, private static functions doesn't even need to be declared in the he
31
31
32
32
Data is information, facts etc. An algorithm is code that operates on data.
33
33
34
-
Programming languages, or their libraries, include thoroughly tested algorithms to handle common data structures.
34
+
Programming languages, or their libraries, include thoroughly tested algorithms to handle common data structures.
35
35
36
36
By properly considering algorithms and data structure, and keeping data separate from code, both code and data become simpler, more reliable, more flexible, and easier to maintain for the next person.
Copy file name to clipboardExpand all lines: bestpractices/codereview.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,10 @@ You can always consult it to learn more useful stuff.
11
11
12
12
While points of this guide might not be consistently followed throughout all of the existing codebase, checking if new code follows them is possible and in long term should help us immensely.
13
13
14
-
> [!NOTE]
14
+
> [!NOTE]
15
15
> Remember that code review is a collaborative discussion. Don’t hesitate to ask for clarification or help when needed. Reviewers can also make mistakes, the goal is to work together to refine the code to a point where everyone is satisfied.
16
16
17
-
In this document the **bolded** text will indicate how important each suggestion is.
17
+
In this document the **bolded** text will indicate how important each suggestion is.
18
18
-**must** will be used for fundamental things that should be non-controversial and which you really should follow
19
19
-**should** will be used for important details that will apply for vast majority of cases, there could however be valid reasons to ignore them depending on context
20
20
-**could** will be used for best practices, things that you should try to follow but not following them is not an error per se
@@ -38,11 +38,11 @@ In this document the **bolded** text will indicate how important each suggestion
38
38
4. Early-Exit **should** be preferred to prune unwanted execution branches fast.
39
39
7. Global state (global variables, static fields, singletons) **should be** avoided.
40
40
8. (C++ only) `enum class`**should** be preferred over normal enum whenever possible.
41
-
9. (C++ only) C++ libraries/structures **should** be preferred over C ones. i.e. `std::array/vector` should be used instead of C array.
41
+
9. (C++ only) C++ libraries/structures **should** be preferred over C ones. i.e. `std::array/vector` should be used instead of C array.
42
42
10. (C++ only) C++ standard library **should** be utilized if possible, especially the `<algorithms>` one.
43
43
<details>
44
44
<summary>Example #1</summary>
45
-
45
+
46
46
Consider following code:
47
47
```c++
48
48
std::vector<int> vertices;
@@ -87,7 +87,7 @@ In this document the **bolded** text will indicate how important each suggestion
87
87
14. All members **must** be initialized.
88
88
<details>
89
89
<summary>Rationale</summary>
90
-
Not initialized members can easily cause undefined behaviors that are really hard to find.
90
+
Not initialized members can easily cause undefined behaviors that are really hard to find.
91
91
</details>
92
92
93
93
## Design / Architecture
@@ -105,7 +105,7 @@ In this document the **bolded** text will indicate how important each suggestion
105
105
5. Long methods **should** be split into smaller, better described ones.
106
106
6. (C++ only) Defining new macros **must** be avoided, unless absolutely necessary.
107
107
7. Integers **must not** be used to express anything other than numbers. For enumerations enums **must** be used.
108
-
8. Code **should** be written in a way that it expresses intent, i.e. what should be done, rather than just how it is done.
108
+
8. Code **should** be written in a way that it expresses intent, i.e. what should be done, rather than just how it is done.
109
109
<details>
110
110
<summary>Example #1</summary>
111
111
Consider this code:
@@ -115,7 +115,7 @@ In this document the **bolded** text will indicate how important each suggestion
115
115
// ... some code ...
116
116
117
117
QDockWidget *dock = nullptr;
118
-
118
+
119
119
for (auto w = qApp->widgetAt(QCursor::pos()); w; w = w->parentWidget()) {
120
120
dock = qobject_cast<QDockWidget*>(w);
121
121
if (dock) {
@@ -144,10 +144,10 @@ In this document the **bolded** text will indicate how important each suggestion
144
144
toggleOverlay(dock, m);
145
145
}
146
146
```
147
-
148
-
It is hard to understand what is the job of the for loop inside `if (!dock)` statement.
147
+
148
+
It is hard to understand what is the job of the for loop inside `if (!dock)` statement.
149
149
We can refactor it to a new `QWidget* findClosestDockWidget()` method for it to look like this:
150
-
150
+
151
151
```c++
152
152
void setOverlayMode(OverlayMode mode)
153
153
{
@@ -168,27 +168,27 @@ In this document the **bolded** text will indicate how important each suggestion
168
168
169
169
That way reading through code of `setOverlayMode` we don't need to care about the details of finding the closest dock widget.
170
170
</details>
171
-
10. Boolean arguments **must** be avoided. Use enumerations instead - enum with 2 values is absolutely fine.
171
+
10. Boolean arguments **must** be avoided. Use enumerations instead - enum with 2 values is absolutely fine.
172
172
For python boolean arguments are ok, but they **must** forced to be keyword ones.
173
173
<details>
174
174
<summary>example #1 (c++)</summary>
175
175
consider following example:
176
-
176
+
177
177
```c++
178
178
mapper.populate(false, it.key(), it.value());
179
179
```
180
180
181
181
it is impossible to understand what false means without consulting the documentation or at least the method signature.
0 commit comments