Naming

From ScorecWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 18:28, 3 August 2010
Weisse (Talk | contribs)
(Function - updated abbreviation policy per today's meeting.)
← Previous diff
Revision as of 18:31, 3 August 2010
Weisse (Talk | contribs)
(Variable)
Next diff →
Line 39: Line 39:
-'''<_>''' denotes something is a member variable of a class.+'''<_>''' denotes something is a member variable of a class. If a variable is not a member of a class, omit the underscore.
Example: _i_Counter Example: _i_Counter

Revision as of 18:31, 3 August 2010

Contents

File Names

  • In C++ language, file name is <base name>[_section].<extension> (<>: mandatory item, []: optional item)
  • <base name> shall only use English letter, number and ‘_’.
  • <base name> shall begin with an uppercase letter.
  • When denominating with verb and noun, array <verb><noun> order and shall not combine with more than four words.
  • File name shall not have more than 31 letters.
  • The name of file which declares class shall be class name.
  • interface files should be named by their abbreviation: FMDB.h, MA.h, GMI.h, AMSI.h, IPCM.h.

Namespace

The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design as follows: SCOREC::TechnologyName::Feature::Design. Remember all namespaces should be contained in the SCOREC namespace.

Example: SCOREC::MCTK::Field

Class

  • In general, can refer to the naming convention of Files and Functions regarding the length of a class name and usage of upper or lower case letters.
  • The following guidelines are from web http://msdn.microsoft.com/en-us/library/ms229040.aspx
    • Do name classes, interfaces, and value types with nouns, noun phrases, or occasionally adjective phrases, using Pascal casing.
    • Do not give class names a prefix (such as the letter C).

Interfaces, which should begin with the letter I, are the exception to this rule. ( NOT SURE ABOUT THIS )

    • Consider ending the name of derived classes with the name of the base class.

For example, Framework types that inherit from Stream end in Stream, and types that inherit from Exception end in Exception.

    • Do prefix interface names with the letter I to indicate that the type is an interface. ( SAME AS ABOVE, NOT SURE ABOUT THIS )
    • Do ensure that when defining a class/interface pair where the class is a standard implementation of the interface, the names differ only by the letter I prefix on the interface name.

For example, the Framework provides the IAsyncResult interface and the AsyncResult class.

Function

  • Use abbreviations for long words.
  • When denominating with verb and noun, list in <verb><noun> order and shall not combine with more than four words
  • Function name consists of English characters and numbers only
  • Function name shall not have more than 31 letters
  • Function name begin with an uppercase letter
  • If function name is made up with more than a word, each word shall begin with an uppercase letter. (In case of using prefix expressing certain block, module or function, ‘_’ can be used)

Variable

Variables are named in the form:

<_><s><g><p><data type>_<data member name>


<_> denotes something is a member variable of a class. If a variable is not a member of a class, omit the underscore.

Example: _i_Counter


<s><g><p> These prefixes can be omitted if not applicable to the variable. A variable with none of these prefixes is assumed to be local.

  • p - pointer variable name
  • g - global variable name
  • s - static variable name
Example: pi_Counter


<data type> Data type prefixes for variables:

  • C data types
    • v - void
    • i - int
    • f - float
    • d - double
    • c - char
  • C++ data types
    • b - boolean
  • Other
    • st - structure
    • un - union
    • For the stl containers, use the <container type><data member name> template. For example, std::list LstNodes. See the abbreviations for STL.
    • obj - object. Use this for any non-standard class.

Note that we do not indicate type modifiers (short, long, unsigned, signed). So, for example, an int is indicated by an "i" regardless if it is a short or a long.


<data member name>

  • CamelCase VariableNames - If name is made up of more than a word, each word should begin with an uppercase letter.

Examples:

  • i_VariableName - integer variable VariableName.
  • ii_VariableName - matrix of integer VariableName
  • pi_VariableName - pointer to an integer variable VariableName.
  • sgpi_VariableName - pointer to static global integer variable VariableName.
  • _pi_VariableName - pointer to a member variable VariableName in some class.
  • ppc_VariableName - pointer to a pointer to a char variable VariableName.
  • pVtx_VariableName - pointer to an object of class Vtx with the name VariableName.
  • Vec_VariableName - stl vector with the name VariableName

Other comments:

  • How to differentiate between a class and a typedef?
    • It is not necessary to.
Personal tools