Cpp Coding Standards/GEN
- 1 General Coding (GEN)
- 1.1 Const Correctness (Const)
- 1.2 Resource Allocation is Initialization (RAII)
- 1.3 Avoid Duplicate Code (Dupli)
- 1.4 Initialize Everything Immediately (Init)
- 1.5 Optimize Later (Opti)
- 1.6 Clear Origin of Local Data (LocalData)
- 1.7 Local Conventions (LocalConv)
- 1.8 Matching Array Delete (ArrayDel)
- 1.9 Related Rules
General Coding (GEN)
General advice for coding.
Const Correctness (Const)
Make every member function const that does not change the logical state of its class. Use “mutable” to distinguish logical from physical state.
Prefer constants over variables wherever possible. -> Details
Resource Allocation is Initialization (RAII)
Use the “Resource acquisition is initialization” (RAII) idiom to manage resources.
Use smart pointers for objects on the heap. -> Details
Avoid Duplicate Code (Dupli)
Avoid and remove duplicate code. Duplicate code may be okay, if otherwise dependencies among so far unrelated modules would be created. Among constructors of the same class some code duplication is okay. -> Details
Initialize Everything Immediately (Init)
Initialize all variables at declaration.
Every struct needs a constructor.
Preferably mention every data member, including the default constructed ones, in the constructor's initialization section. -> Details
Optimize Later (Opti)
Do not optimize before you really know there is a performance problem. Use inline sparingly. However do optimize in algorithm complexity. -> Details
Clear Origin of Local Data (LocalData)
Use a consistent way to distinguish member data, local variables and function parameters. -> Details
Local Conventions (LocalConv)
When changing code in a module, follow local naming conventions. -> Details
Matching Array Delete (ArrayDel)
When using new, employ a matching delete statement. -> Details
Preferred Types -> OBSOLETE:Types