Google
 

8/23/07

C++ Naming Standards (DRAFT)

It is helpful to use the name convention consistently when you write the program. In this site I got the following "standard". I think it is very useful so I copy it here.


The following standards are intended to provide guidance for development of names defined within C++ programs developed by the IHFS project. The standards are derived from the C++ Coding Standards developed by the European Laboratory for Particle Physics (CERN) which can be found at http://axaonl.cern.ch:8000/a_doc$www/ONLINE/CXX_CODING_STANDARDS.HTML#names

All Upper Case Abbreviations

All upper case abbreviations are acceptable when the abbreviation is well known and in common use. e.g. - RFC

Class Names

Use upper case letters as word separators, lower case for the rest of a word First character in a name is upper case No underscores '_'

Class Library Names

Until Namespaces are widely implemented in C++, libraries in danger of conflicting with other libraries should choose some sort of unique prefix to avoid name conflicts. It's common for a prefix to be two characters, but a longer length is acceptable.

Method Names

Use the same rule as for class names.

Class Attribute Names

Use lower case attribute names Separate keywords with underscores '_'

Method Argument Names

The first character should be lower case. All words beginning after the first letter should be upper case as with class names.

Variable Names on the Stack

use all lower case letters use underscore '_' as the word separator.

Pointer Variables

Pointers should be prefixed by a 'ptr' Place the * close to the pointer type not the variable name

Reference Variables

References should be prefixed with 'ref'

Global Variables

Global variables should be prefixed with 'glo'.

Static Variables

Static variables should be prefixed with 'sta'

Type Names

When possible, make a typedef for types based on builtin types. Typedef names should use the same naming policy as for a class with the word Type appended.

C Function Names

In a C++ project there should be very few C functions. For C functions use the GNU convention of all lower case letters with '_' as the word delimiter.

Enum Names

Labels All Upper Case with '_' Word Separators

No comments: