Difference between revisions of "Cpp Coding Standards"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m (Purpose: Typo fixed.)
 
(33 intermediate revisions by one other user not shown)
Line 1: Line 1:
This page gathers rules, advice and best practices for developing with C++ in the [[OpenOffice.org]] project.
+
=== Purpose ===
 +
[[Coding Standards]] are a part of [[defect prevention]]. They gather rules, advice and best practices for developing software, especially the code writing part. Here are listed some ideas what such standards could be for developing with C++ and within the [[OpenOffice.org]] project.
 +
 
 +
=== Standards and Reviews  ===
 +
Coding standards and reviews are related. Reviews help getting to know standards and bringing them into the real life of the code. Reviews also help to improve standards and disclose needed changes.
 +
 
 +
The standards are parted into topics. Each topic is intended to cover an area that is small enough to be the focus of a code review session. The summary of rules regarding one topic should not cover more than "one page" of paper or on screen. This way one topic's summary can be printed out and be used as checklist when studying code.
 +
 
 +
To print a summary page out of this wiki such that it fits on one page indeed, select the text of the rule summaries (all text below the content table) and print using the option "print selection".
 +
 
 +
Most times a summary alone is not enough to understand and discuss a rule, also there are exceptions and hints for realization. So, for each rule there will be a separate wiki page to discuss it.
 +
 
 +
=== Identifying Rules ===
 +
Every topic and each item have an id.
 +
 
 +
Ids enable to make notes about rules (e.g. during reviews) and help when talking about them. The ids are not just cardinal numbers, but strings, because strings do not change, when other items are added or removed.
 +
 
 +
Example: [[/FDESIGN#OneTask | FDESIGN:OneTask]] is the rule with the id ''OneTask'' which belongs to the topic [[/FDESIGN|Function Design]] with the id ''FDESIGN''.
 +
 
 
----
 
----
=== Class Design ===
 
General hints for class design. Items referring to constructors, destructors, copying and allocation (of classes) reside in topic “Class Initialization”. Items referring to virtual classes in hierarchies reside in “Hierarchies of Virtual Classes”. Encapsulation related items are in topic “Encapsulation”.
 
  
==== OneResponsibility ====
+
=== Topics by Problem Domain ===
Give one class only one cohesive responsibility.
+
''Topics may appear at multiple domains.''
  
==== Inherit ====
+
==== Design ====
Inherit to be reused, not to reuse. Else prefer composition over inheritance.
+
* [[/DESIGN|Design]] (DESIGN)
 +
* [[/VIRTUAL|Virtual Classes]] (VIRTUAL)
 +
* [[/CLSDESIGN|Class Design]] (CLSDESIGN)
 +
* [[/IFC|Interfaces]] (IFC)
 +
* [[/FDESIGN|Function Design]] (FDESIGN)
  
==== NoImplicitConversions ====
+
==== Classes ====
Make single argument constructors “explicit”. Be aware of default arguments.
+
* [[/CLSDESIGN|Class Design]] (CLSDESIGN)
Do not provide operator TYPE() functions.
+
* [[/VIRTUAL|Virtual Classes]] (VIRTUAL)
 +
* [[/IFC|Interfaces]] (IFC)
 +
* [[/ENC|Encapsulation]] (ENC)
 +
* [[/CLSINIT|Class Construction, Destruction and Copying]] (CLSINIT)
 +
* [[/FDESIGN|Function Design]] (FDESIGN)  
  
==== SpecificNewDelete ====
+
==== Functions and Implementation Generally ====
When you provide a class-specific new or delete with custom parameters, provide the corresponding new or delete as well. (Not doing this causes memory leaks.)
+
* [[/GEN|General Coding]] (GEN)  
If you provide one class specific new, this hides all other variants of new. So you probably want to provide also the three all of the standard forms of new (plain, nothrow and inplace).
+
* [[/FDESIGN|Function Design]] (FDESIGN)
 +
* [[/FIMPL|Function Implementation]] (FIMPL)
 +
* [[/ERR|Error Handling]] (ERR)
 +
* [[/SECURITY|Security]] (SECURITY)
  
 +
==== Preferred vs. Discarded Types and Habits ====
 +
* [[/STL|The C++ Standard Template Library]] (STL)
 +
* [[/TYPE|Type Safety]] (TYPE)
 +
* [[/OBSOLETE|Obsolete Habits]] (OBSOLETE)
  
Class Construction, Destruction and Copying
+
==== Files, Formatting, Documentation ====
 +
* [[/CODEDOC|Code Documentation]] (CODEDOC)
 +
* [[/HEADERS|Header Files]] (HEADERS)
 +
* [[/FORMAT|Code Format]] (FORMAT)
 +
----
  
=== Code Documentation ===
+
=== Topics in Alphabetical Order ===
=== Design ===
+
* [[/CLSINIT|Class Construction, Destruction and Copying]] (CLSINIT)
=== Encapsulation ===
+
* [[/CLSDESIGN|Class Design]] (CLSDESIGN)
=== Error Handling ===
+
* [[/CODEDOC|Code Documentation]] (CODEDOC)
=== Code Format ===
+
* [[/FORMAT|Code Format]] (FORMAT)
=== Function Design ===
+
* [[/DESIGN|Design]] (DESIGN)
=== Function Implementation ===
+
* [[/ENC|Encapsulation]] (ENC)
=== General Coding ===
+
* [[/ERR|Error Handling]] (ERR)
=== Header Files ===
+
* [[/FDESIGN|Function Design]] (FDESIGN)
=== Hierarchies of Virtual Classes ===
+
* [[/FIMPL|Function Implementation]] (FIMPL)
=== Interfaces ===
+
* [[/GEN|General Coding]] (GEN)
=== Obsolete Habits ===
+
* [[/HEADERS|Header Files]] (HEADERS)
=== Security ===
+
* [[/IFC|Interfaces]] (IFC)
=== The C++ Standard Template Library ===
+
* [[/OBSOLETE|Obsolete Habits]] (OBSOLETE)
=== Type Safety ===
+
* [[/SECURITY|Security]] (SECURITY)
 +
* [[/STL|The C++ Standard Template Library]] (STL)
 +
* [[/TYPE|Type Safety]] (TYPE)
 +
* [[/VIRTUAL|Virtual Classes]] (VIRTUAL)
 +
----
 +
 
 +
=== Guidelines ===
 +
''Not easily checkable or not code related.''
 +
 
 +
* [[/Principles|Principles]] (PRINC)
 +
* [[/Development Process|Development Process]] (PROCESS)
 +
* [[/Advice|Advice]] - (ADVICE)
 +
 
 +
----
 +
[[Category:Coding Standards]]

Latest revision as of 09:31, 14 June 2007

Purpose

Coding Standards are a part of defect prevention. They gather rules, advice and best practices for developing software, especially the code writing part. Here are listed some ideas what such standards could be for developing with C++ and within the OpenOffice.org project.

Standards and Reviews

Coding standards and reviews are related. Reviews help getting to know standards and bringing them into the real life of the code. Reviews also help to improve standards and disclose needed changes.

The standards are parted into topics. Each topic is intended to cover an area that is small enough to be the focus of a code review session. The summary of rules regarding one topic should not cover more than "one page" of paper or on screen. This way one topic's summary can be printed out and be used as checklist when studying code.

To print a summary page out of this wiki such that it fits on one page indeed, select the text of the rule summaries (all text below the content table) and print using the option "print selection".

Most times a summary alone is not enough to understand and discuss a rule, also there are exceptions and hints for realization. So, for each rule there will be a separate wiki page to discuss it.

Identifying Rules

Every topic and each item have an id.

Ids enable to make notes about rules (e.g. during reviews) and help when talking about them. The ids are not just cardinal numbers, but strings, because strings do not change, when other items are added or removed.

Example: FDESIGN:OneTask is the rule with the id OneTask which belongs to the topic Function Design with the id FDESIGN.


Topics by Problem Domain

Topics may appear at multiple domains.

Design

Classes

Functions and Implementation Generally

Preferred vs. Discarded Types and Habits

Files, Formatting, Documentation


Topics in Alphabetical Order


Guidelines

Not easily checkable or not code related.


Personal tools