Name conventions

Select C++ identifiers (including types, functions, and classes) carefully. When a programmer sees a name, it might be out of context; choose names to enhance readability and comprehension. A name that seems cute or easy to type can cause trouble to someone trying to decipher code. Remember, code is read many more times than it is written; err on the side of long, readable names. Internal code names should not appear anywhere in the interfaces to the system. Even inside your implementation, it's better to use the prosaic form if there is one.

To make the scope of names explicit, Taligent uses the following conventions.

Name conventions Identifier Convention Example
Types Begin with a capital letter Boolean
Base classes Begin with T TContainerView
Mixin classes Begin with M;
see "Multiple inheritance" on page 44
MPrintable
Enumeration types Begin with E EFreezeLevel
Raw C types Avoid using C types; see "Avoid raw C types with dimensions" on page 66
Virtual base classes Begin with V, rather than T or M VBaseClass
Members Begin with f for field1;
functions begin with a capital letter
fViewList, DrawSelf()
Static variables Begin with g; applies to static variables in functions and global variables (excluding static data members of a class) gDeviceList
Static data members Begin with fg; includes class globals TView::fgTokenClient
Locals and parameters Begin with a word whose initial letter is lowercase; local automatic variables only, treat statics like globals seed, port,
theCurrentArea
Constants Begin with k; including names of enumeration constants and constant statics kMenuCommand
Acronyms All uppercase TNBPName, not TNbpName
Template arguments Begin with A AType
Getters and setters Begin with Set..., Get..., or Is... (Boolean); use sparingly (see "Structification" on page 50) SetLast(), GetNext(), IsDone()
Allocator and adopters Begin with Create..., Copy..., Adopt..., or Orphan...; see "Use special names for copy, create, and adopt routines" on page 61 CreateName()
1Field is a historical name for data member

In any name that contains more than one word, the first word follows the convention for the type of the name, and subsequent words follow with the first letter of each word capitalized, such as TTextBase. Do not use underscores except for #define symbols.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker