NCCA Coding Standard Style and Practice

General Coding Style and Practices

  • All indenting should be use with Tabs, set to a standard size of 2 spaces and if possible set the editor to replace tabs with spaces.

  • Always specify single precision for floating point values unless there is an explicit need for a double i.e. float a=0.2f; rather than float a=0.2;
  • All code should compile without warnings on the highest warning level supported by the compiler. Warnings that are allowed will be explicitly disabled by the core engine and project includes.
  • Namespaces will always be used for project code however the use of using namespace .... `` is prohibited. For example std::cout``` must be used. If namespaces are long use an alias.
  • When using pointers, nullptr will always be used instead of NULL (NULL is not part of C++)
  • Wherever possible use smart pointers (std::unique_ptr<>)
  • Be prepared to defend all uses of static and global variables in your next code review.
  • Where functions return an error state, true should always indicate success.
  • Always use std containers and algorithms first before designing your own, they will usually be fine.
  • if in doubt it is most likely you need std::vector<>

Naming convention

All #define name should be all uppercase with underscores separating words. The letters of an acronym should not be separated. If you are going to use a group identifier, like “GLIB” or “"“ENGINE” then that should be the first word in the name. The only exception to these rules are the #defines used around header file includes - these need not contain underscores to separate words.

Inline functions, constants, constexpr and enumerations are all preferable to preprocessor macros where they can be used.

Where macros evaluate to expressions, the body of the macro should always be bracketed.

Examples:

#define GE_RGBA_SHIFT_BLUE  (16)
#define MAX_LINE_LEN        (BUFFER_SIZE - 1)
#define MAX(a, b)           ((a) < (b) ? (b) : (a))
#define DEBUG_RENDER_ON     (1)

With the exception of the include guards, conditional compilation macros should always evaluate to a value so they can be evaluated with #if. #ifdef should only be used to detect if a macro has never been defined.

So, this is ok :

#define DEBUG_RENDER_ON     (1)

This is not ok :

#define DEBUG_RENDER_ON     

Type Names

All type names have the first letter of each word lower case, followed by a capital for the Next work as per the Qt coding standard.

int checkStatusAndReturn;
float deltaPhi;
float metersPerSecond;

Variable Names

All variable names should be self-explanatory where possible, with the first letter in lower case, and the first letter of each subsequent word in upper-case (However, if the first part of the variable name is an abbreviation that has already been uppercased in other parts of the code, then use the uppercase abbreviation in the variable name). No underscores should be used, other than in prefixes and postfixes. Hungarian prefixing should not be used.

Single letter variable names may only be used for short loops. If the loop spans more than a few lines, use a full length variable name.

Variables use the following prefixes :

 g_ : Global variable
 c_ : Constant
 _ : Input-only function parameter
 o_ : Output-only function parameter
 io_ : Input-Output function parameter
 m_ : Class member
 s_ : Static class member

This is ok :

 m_randomClassPointer
 m_textBuffer

This is not ok:

m_RandomClassPointer
m_szTextBuffer
Previous
Next