Skip to content

Commit 5c73400

Browse files
committed
Add a new section on maintainability
1 parent 6d21a04 commit 5c73400

9 files changed

+37
-26
lines changed

00-Table_of_Contents.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
2. [Use the Tools Available](02-Use_the_Tools_Available.md)
44
3. [Style](03-Style.md)
55
4. [Considering Safety](04-Considering_Safety.md)
6-
5. [Considering Portability](05-Considering_Portability.md)
7-
6. [Considering Threadability](06-Considering_Threadability.md)
8-
7. [Considering Performance](07-Considering_Performance.md)
9-
8. [Enable Scripting](08-Enable_Scripting.md)
10-
9. [Further Reading](09-Further_Reading.md)
11-
10. [Final Thoughts](10-Final_Thoughts.md)
6+
5. [Considering Maintainability](05-Considering_Maintainability.md)
7+
6. [Considering Portability](06-Considering_Portability.md)
8+
7. [Considering Threadability](07-Considering_Threadability.md)
9+
8. [Considering Performance](08-Considering_Performance.md)
10+
9. [Enable Scripting](09-Enable_Scripting.md)
11+
10. [Further Reading](10-Further_Reading.md)
12+
11. [Final Thoughts](11-Final_Thoughts.md)
1213

1314

03-Style.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,31 +271,13 @@ Forgetting to initialize a member is a source of undefined behavior bugs which a
271271

272272
There is almost never a reason to declare an identifier in the global namespaces. Instead, functions and classes should exist in an appropriately named namespace or in a class inside of a namespace. Identifiers which are placed in the global namespace risk conflicting with identifiers from other libraries (mostly C, which doesn't have namespaces).
273273

274-
## Avoid Compiler Macros
275-
276-
Compiler definitions and macros are replaced by the preprocessor before the compiler is ever run. This can make debugging very difficult because the debugger doesn't know where the source came from.
277-
278-
```cpp
279-
// Bad Idea
280-
#define PI 3.14159;
281-
282-
// Good Idea
283-
namespace my_project {
284-
class Constants {
285-
public:
286-
// if the above macro would be expanded, then the following line would be:
287-
// static const double 3.14159 = 3.14159;
288-
// which leads to a compile-time error. Sometimes such errors are hard to understand.
289-
static const double PI = 3.14159;
290-
}
291-
}
292-
```
293-
294274

295275
## Use the Correct Integer Type For stdlib Features
296276

297277
The standard library generally returns `size_t` for anything related to size. What exactly `size_t` is is implementation defined.
298278

279+
In general, using `auto` will avoid most of these issues, but not all.
280+
299281
Make sure you stick with the correct integer types and remain consistent with the C++ stdlib. It might not warn on the platform you are currently using, but it probably will when you change platforms.
300282

301283
## Use .hpp and .cpp for Your File Extensions

05-Considering_Maintainability.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Considering Maintainability
2+
3+
4+
## Avoid Compiler Macros
5+
6+
Compiler definitions and macros are replaced by the preprocessor before the compiler is ever run. This can make debugging very difficult because the debugger doesn't know where the source came from.
7+
8+
```cpp
9+
// Bad Idea
10+
#define PI 3.14159;
11+
12+
// Good Idea
13+
namespace my_project {
14+
class Constants {
15+
public:
16+
// if the above macro would be expanded, then the following line would be:
17+
// static const double 3.14159 = 3.14159;
18+
// which leads to a compile-time error. Sometimes such errors are hard to understand.
19+
static const double PI = 3.14159;
20+
}
21+
}
22+
```
23+
24+
25+
26+
## Avoid Raw Loops
27+
28+
Know and understand the existing C++ standard algorithms and put them to use. See [C++ Seasoning](https://www.youtube.com/watch?v=qH6sSOr-yk8) for more details.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)