Difference between revisions of "Cpp Coding Standards/GEN"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Topic-Id: '''GEN'''
+
== General Coding (GEN) ==
 +
''General advice for coding.''
 +
===== Const Correctness <span id="Const">(Const)</span> =====
 +
Make every member function const that does not change the logical state of its class. Use “mutable” to distinguish logical from physical state.<br>
 +
Prefer constants over variables wherever possible. [[/Const|-&gt; Details]]
  
General advice for coding.
+
===== Resource Allocation is Initialization <span id="RAII">(RAII)</span> =====
----
+
Use the “Resource acquisition is initialization” (RAII) idiom to manage resources.<br>
=== Summary ===
+
Use smart pointers for objects on the heap. [[/RAII|-> Details]]
==== Const Correctness <span id="Const">(Const)</span> ====
+
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.
+
===== Avoid Duplicate Code <span id="Dupli">(Dupli)</span> =====
 +
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. [[/Dupli|-> Details]]
  
[[/Const|Details]]
+
===== Initialize Everything Immediately <span id="Init">(Init)</span> =====
 +
Initialize all variables at declaration. <br>
 +
Every struct needs a constructor. <br>
 +
Preferably mention every data member, including the default constructed ones, in the constructor's initialization section. [[/Init|-> Details]]
  
==== Resource Allocation is Initialization <span id="RAII">(RAII)</span> ====
+
===== Optimize Later <span id="Opti">(Opti)</span> =====
Use the “Resource allocation is initialization” (RAII) idiom to manage resources.
+
Do not optimize before you really know there is a performance problem. Use inline sparingly. However do optimize in algorithm complexity. [[/Opti|-> Details]]
  
Use smart pointers for objects on the heap.
+
===== Clear Origin of Local Data <span id="LocalData">(LocalData)</span> =====
 +
Use a consistent way to distinguish member data, local variables and function parameters. [[/LocalData|-> Details]]
  
[[/RAII|Details]]
+
===== Local Conventions <span id="LocalConv">(LocalConv)</span> =====
 
+
When changing code in a module, follow local naming conventions. [[/LocalConv|-> Details]]
==== Avoid Duplicate Code <span id="Dupli">(Dupli)</span> ====
+
Avoid and remove dupliate 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.
+
 
+
[[/Dupli|Details]]
+
 
+
==== Initialize Everything Immediately <span id="Init">(Init)</span> ====
+
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.
+
 
+
[[/Init|Details]]
+
 
+
==== Optimize Later <span id="Opti">(Opti)</span> ====
+
Do not optimize before you really know there is a performance problem. Use inline sparingly. However do optimize in algorithm complexity.
+
 
+
[[/Opti|Details]]
+
 
+
==== Clear Origin of Local Data <span id="LocalData">(LocalData)</span> ====
+
Use a consistent way to distinguish member data, local variables and function parameters.
+
 
+
[[/LocalData|Details]]
+
 
+
==== Local Conventions <span id="LocalConv">(LocalConv)</span> ====
+
When changing code in a module, follow local naming conventions.
+
 
+
[[/LocalConv|Details]]
+
 
+
==== Matching Array Delete <span id="ArrayDel">(ArrayDel)</span> ====
+
When using new[], employ a matching delete[] statement.
+
 
+
[[/ArrayDel|Details]]
+
  
 +
===== Matching Array Delete <span id="ArrayDel">(ArrayDel)</span> =====
 +
When using new[], employ a matching delete[] statement. [[/ArrayDel|-> Details]]
 
----
 
----
=== Related Rules ===
+
==== Related Rules ====
* [[../Obsolete Habits#Types |OBSOLETE:Types]] - Preferred Types
+
'''Preferred Types''' [[../Obsolete Habits#Types |-> OBSOLETE:Types]]
 
+
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Latest revision as of 09:14, 23 May 2007

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


Related Rules

Preferred Types -> OBSOLETE:Types


Personal tools