Skip to content

Commit b29e281

Browse files
committed
Best Practices: Trim trailing whitespace
1 parent a852fe9 commit b29e281

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

bestpractices/c++practices.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ layout: default
44

55
# C++ practices
66

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).
88
Whenever something is not covered or you are in doubt - don't hesitate to consult it - it is a very good source of information.
99

1010
## Avoid anonymous namespaces
@@ -31,7 +31,7 @@ In addition, private static functions doesn't even need to be declared in the he
3131

3232
Data is information, facts etc. An algorithm is code that operates on data.
3333

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

3636
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.
3737

@@ -106,7 +106,7 @@ static constexpr std::array<PrefixSpec, 7> sortedPrefixes {
106106
{'M', 1ULL << 20}, // 1 << 20 = 2^20 = 1024
107107
{'k', 1ULL << 10}, // 1 << 10 = 2^10 = 1024
108108
{'\0', 0}}};
109-
109+
110110
const auto res = std::find_if(prefixes.begin(), prefixes.end(), [&](const auto& spec) {
111111
return spec.factor <= size;
112112
});
@@ -212,7 +212,7 @@ A function which has hard dependencies cannot function, be understood, edited or
212212
213213
Code and its dependencies are said to be _coupled._ When different pieces of code _have the same_ dependency, they in turn are coupled to each other.
214214
215-
Required information can be injected via constructor or method parameters.
215+
Required information can be injected via constructor or method parameters.
216216
217217
If it is necessary to introduce external code (e.g. a service object), do so by passing an interface, helper function or similar to avoid coupling.
218218
@@ -393,7 +393,7 @@ when removing repetition.
393393
Whilst lambdas are quite happy with simple auto parameters, best not
394394
to omit const or & as appropriate. Types may be required to help the IDE.
395395

396-
Consider the following code:
396+
Consider the following code:
397397
```c++
398398
doSomething()
399399
if (somethingWentWrong()) {
@@ -605,4 +605,4 @@ constexpr std::array<Button, numButtons> buttonDefs {{
605605
}};
606606
```
607607
608-
When in doubt, use a struct - it is better to have good names than not.
608+
When in doubt, use a struct - it is better to have good names than not.

bestpractices/codereview.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ You can always consult it to learn more useful stuff.
1111

1212
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.
1313

14-
> [!NOTE]
14+
> [!NOTE]
1515
> 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.
1616
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.
1818
- **must** will be used for fundamental things that should be non-controversial and which you really should follow
1919
- **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
2020
- **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
3838
4. Early-Exit **should** be preferred to prune unwanted execution branches fast.
3939
7. Global state (global variables, static fields, singletons) **should be** avoided.
4040
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.
4242
10. (C++ only) C++ standard library **should** be utilized if possible, especially the `<algorithms>` one.
4343
<details>
4444
<summary>Example #1</summary>
45-
45+
4646
Consider following code:
4747
```c++
4848
std::vector<int> vertices;
@@ -87,7 +87,7 @@ In this document the **bolded** text will indicate how important each suggestion
8787
14. All members **must** be initialized.
8888
<details>
8989
<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.
9191
</details>
9292

9393
## Design / Architecture
@@ -105,7 +105,7 @@ In this document the **bolded** text will indicate how important each suggestion
105105
5. Long methods **should** be split into smaller, better described ones.
106106
6. (C++ only) Defining new macros **must** be avoided, unless absolutely necessary.
107107
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.
109109
<details>
110110
<summary>Example #1</summary>
111111
Consider this code:
@@ -115,7 +115,7 @@ In this document the **bolded** text will indicate how important each suggestion
115115
// ... some code ...
116116

117117
QDockWidget *dock = nullptr;
118-
118+
119119
for (auto w = qApp->widgetAt(QCursor::pos()); w; w = w->parentWidget()) {
120120
dock = qobject_cast<QDockWidget*>(w);
121121
if (dock) {
@@ -144,10 +144,10 @@ In this document the **bolded** text will indicate how important each suggestion
144144
toggleOverlay(dock, m);
145145
}
146146
```
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.
149149
We can refactor it to a new `QWidget* findClosestDockWidget()` method for it to look like this:
150-
150+
151151
```c++
152152
void setOverlayMode(OverlayMode mode)
153153
{
@@ -168,27 +168,27 @@ In this document the **bolded** text will indicate how important each suggestion
168168

169169
That way reading through code of `setOverlayMode` we don't need to care about the details of finding the closest dock widget.
170170
</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.
172172
For python boolean arguments are ok, but they **must** forced to be keyword ones.
173173
<details>
174174
<summary>example #1 (c++)</summary>
175175
consider following example:
176-
176+
177177
```c++
178178
mapper.populate(false, it.key(), it.value());
179179
```
180180

181181
it is impossible to understand what false means without consulting the documentation or at least the method signature.
182182
instead the enum should be used:
183-
183+
184184
```c++
185185
mapper.populate(mappingstatus::modified, it.key(), it.value());
186186
```
187187

188188
now the intent is clear
189189
</details>
190190
11. (C++ only) Code **should** prefer uniform initialization `{ }` (also called brace initialization). Prevents narrowing.
191-
12. (C++ only) Class member variables **should** be initialized at declaration, not in constructors
191+
12. (C++ only) Class member variables **should** be initialized at declaration, not in constructors
192192
13. Magic numbers or other literals **must** be avoided.
193193

194194

bestpractices/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ layout: default
55
# Best Practices
66

77
Although this chapter is not FreeCAD specific, it is provided here to help both developers and code reviewers to ensure
8-
clean and easily maintainable code. The practices presented should be treated like food recipes - you can play with them,
8+
clean and easily maintainable code. The practices presented should be treated like food recipes - you can play with them,
99
alter them - but every change should be thoughtful and intentional.
1010

11-
While this guideline might not be consistently followed throughout all of the existing codebase, adhering to these practices
11+
While this guideline might not be consistently followed throughout all of the existing codebase, adhering to these practices
1212
moving forward will help improve the overall quality of the code and make future contributions more maintainable. Consider it
1313
as inspiration for the better future.
1414

bestpractices/pythonpractices.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Python Practices
22

3-
Work in Progress - looking for help!
3+
Work in Progress - looking for help!

0 commit comments

Comments
 (0)