Notation

  1. The word class shall apply to both classes and structs

Rules

  1. All types shall be named as follows:

    1. Class names shall start with a capital letter.  Each word in the name shall be denoted with a capital letter.  No underscores shall be used in class names.

      • Example: class CommandReturnType

    2. Enum names shall follow the same naming convention as classes with one exception.  The name of an enum shall end in “Enum.”

      • Example: enum CommandCodeEnum

    3. Typedefs shall follow the same naming convention as classes with one exception.  The name of a typedef shall end in “Type.”

      • Example: typedef uint8 CommandCodeType

  2. All functions shall be named as follows:

    1. Class methods shall start with a capital letter.  Each word in the name shall be denoted with a capital letter.  No underscores shall be used in method names.

      • Example: void CommandRegistry::Invoke( );

    2. All method names shall begin with a verb.

      • Example: uint32 CommandHandler::GetEventTime();

    3. Global functions shall start with a lowercase letter.  Each word in the name shall be denoted with a capital letter.  No underscores shall be used in function names.

      • Example: void commServerTask( );

  3. All params shall be named as follows:

    1. First letters of all parameter names shall be lowercase and all subsequent words shall begin with a capital letter.

      • Example void Command::Invoke(uint16 paramOne, char paramTwo);

  4. Namespaces shall be subject to the following rules:

    1. All modules shall define their code in a namespace that defines the functionality of the module.  The namespace shall be named using the same convention as a class.

      • Example: namespace PhoenixCore

      • Example: namespace PhoenixCommServer

  5. Built-in types shall be used as follows:

    1. A char shall only be used when the programmer is referring to an ASCII character.  If an 8-bit variable is desired, then the int8  or uint8 type shall be used.

    2. An int shall only be used when the programmer is referring to a signed integer.  It is preferred that the programmer use the types int16, uint16, int32, uint32, as this disambiguates the size and sign of the variable.

    3. Whenever an index is used in a loop, the type of the index shall reflect the objects being looped through.  For example, when looping through a string and setting the loop variable to a character in the string, a char shall be used.  When looping through an array, std::size_t shall always be used, as this guarantees that no wrap-around will occur.

  6. All header files shall be commented as follows:

    1. Each class, function, enum, file, or other object shall include a doxygen comment that describes the functionality of that object.  All doxygen comments follow the rules below.

    2. All doxygen comments shall follow one of two forms.  For long comments, the doxygen comment shall start with /*! and end with */.  Shorter comments can be placed on the same line as the object being commented (such as a class variable) and use the syntax /*!< Comment */

    3. All functions including "//Constructor" and "//Destructor" shall be commented

  7. All macros and defines shall be named in fully capital letters with underscores separating each word.

  8. All tabs shall be inserted as 4 spaces.  No tab characters shall be used in a source file.

  9. All loops and conditional statements shall use the surrounding curly braces.  Curly braces shall start on the line after the loop or conditional statement at the same indentation level as the statement.  Code within the block shall be indented one level.

  10. Case statements within a switch statement shall be placed at the same indentation level as the switch statement.  Code within each case shall be indented one level.

  11. At all times all checked-in code must compile with the settings for the Phoenix Eclipse project with no warnings or errors.

    1. Lint will be used to check coding standards

    2. All unit tests will be run during compilation.

  12. No trailing whitespace allowed.

  13. Line width shall be constrained to 80 characters per lines.

  14. Between functions in .cpp files slashes shall be used to denote the split.

    1. For example:

      bool foo()

      {

      //Function stuff

}

//////////////////////////////////////////////////////////////////////////

void oof()

{

//oof stuff

}

  1. When comparing a variable to a constant value, the constant shall be located on the left side of the == operator.

    1. Example: if (COMMAND_CODE_PING == code) ...