Difference between revisions of "Cpp Coding Standards/GEN"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m
Line 2: Line 2:
 
General advice for coding.
 
General advice for coding.
 
----
 
----
=== Rules ===
+
=== Summary ===
 
+
 
==== ConstCorrectness ====
 
==== ConstCorrectness ====
 
Make every member function const that does not change the logical state of its class. Use “mutable” to distinguish logical from physical state.
 
Make every member function const that does not change the logical state of its class. Use “mutable” to distinguish logical from physical state.
Line 38: Line 37:
 
=== Related Rules ===
 
=== Related Rules ===
 
* [[../OBSOLETE#PreferredTypes | OBSOLETE:PreferredTypes]]  
 
* [[../OBSOLETE#PreferredTypes | OBSOLETE:PreferredTypes]]  
 +
----
 +
=== Explanations ===
 +
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Revision as of 18:14, 27 November 2006

General Coding

General advice for coding.


Summary

ConstCorrectness

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.

RAII

Use the “Resource allocation is initialization” (RAII) idiom to manage resources.

Use smart pointers for objects on the heap.

AvoidDuplicateCode

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.

InitAll

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.

OptimizeLater

Do not optimize before you really know there is a performance problem. Use inline sparingly. However do optimize in algorithm complexity.

ClearLocalData

Use a consistent way to distinguish member data, local variables and function parameters.

LocalConventions

When changing code in a module, follow local naming conventions.

MatchingDelete

When using new[], employ a matching delete[] statement.----

Related Rules


Explanations


Personal tools