Permalink
Browse files

Add a new section on maintainability

  • Loading branch information...
lefticus committed Jun 8, 2015
1 parent 6d21a04 commit 5c7340061daa7c7d310f08a9c92368ed2430af04
View
@@ -3,11 +3,12 @@
2. [Use the Tools Available](02-Use_the_Tools_Available.md)
3. [Style](03-Style.md)
4. [Considering Safety](04-Considering_Safety.md)
5. [Considering Portability](05-Considering_Portability.md)
6. [Considering Threadability](06-Considering_Threadability.md)
7. [Considering Performance](07-Considering_Performance.md)
8. [Enable Scripting](08-Enable_Scripting.md)
9. [Further Reading](09-Further_Reading.md)
10. [Final Thoughts](10-Final_Thoughts.md)
5. [Considering Maintainability](05-Considering_Maintainability.md)
6. [Considering Portability](06-Considering_Portability.md)
7. [Considering Threadability](07-Considering_Threadability.md)
8. [Considering Performance](08-Considering_Performance.md)
9. [Enable Scripting](09-Enable_Scripting.md)
10. [Further Reading](10-Further_Reading.md)
11. [Final Thoughts](11-Final_Thoughts.md)
View
@@ -271,31 +271,13 @@ Forgetting to initialize a member is a source of undefined behavior bugs which a
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).
## Avoid Compiler Macros
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.
```cpp
// Bad Idea
#define PI 3.14159;
// Good Idea
namespace my_project {
class Constants {
public:
// if the above macro would be expanded, then the following line would be:
// static const double 3.14159 = 3.14159;
// which leads to a compile-time error. Sometimes such errors are hard to understand.
static const double PI = 3.14159;
}
}
```
## Use the Correct Integer Type For stdlib Features
The standard library generally returns `size_t` for anything related to size. What exactly `size_t` is is implementation defined.
In general, using `auto` will avoid most of these issues, but not all.
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.
## Use .hpp and .cpp for Your File Extensions
@@ -0,0 +1,28 @@
# Considering Maintainability
## Avoid Compiler Macros
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.
```cpp
// Bad Idea
#define PI 3.14159;
// Good Idea
namespace my_project {
class Constants {
public:
// if the above macro would be expanded, then the following line would be:
// static const double 3.14159 = 3.14159;
// which leads to a compile-time error. Sometimes such errors are hard to understand.
static const double PI = 3.14159;
}
}
```
## Avoid Raw Loops
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 comments on commit 5c73400

Please sign in to comment.