Coding Standards

From Secret Maryo Chronicles Wiki
Jump to: navigation, search

This document describes the coding standards all developers are expected to adhere to when writing code.

Contents

C++ Standards compliance

Use modern object oriented C++ with STL that is compatible with GNU G++ 3.3 or later and Visual C++ 8 (known also as 2005).

Always prefer C++ techniques over C :

  • Avoid C-strings (char*).
  • Avoid old I/O routines (fopen).
  • Use overloaded methods not varargs.

Indentation

  • The opening and closing brace is placed on the line following the declaration and at the same indentation level as the declaration.
  • Indent your code with a tab character and default tab size is 4 spaces.
  • The use of long lines is allowed.
  • Advantages of this style are that the indented code is clearly set apart from the containing statement by lines that are almost completely whitespace, improving readability and the ending brace lines up in the same column as the beginning brace, making easy to find the matching brace.


Spacing

  • Put a space after the opening parenthesis and the closing one.
  • No space between the function name and the opening parenthesis ( void Update_Item( void ); ).
  • A Space between commas and each parameter ( "jump", "action" ).
  • Always insert spaces in between operators and operands (x + y, not x+y).
  • When declaring pointer data or a function that returns a pointer type, the preferred use of '*' is adjacent to the data name or function name and not adjacent to the type name.

Example :

cEnemy *enemy = new cEnemy( "Furball", 120, 20 );


Casing

  • Each level of the hierarchy separated with a single underscore.


Naming

  • Everything written in American English.
  • Class names should always begin with the prefix "c" (cPlayer).
  • Member variables should be prefixed with 'm_' (m_texture_detail). Do not use the Hungarian notation
  • Code should be self-describing, don't be obtuse.

Comments

  • Single-line comments should always use the "//" C++ style.
  • For a multi-line function declaration comment use the C style :
/*
 * Bla
 * Blorb
 * Blub bla
 */

C++

  • Use inline only if it will result in a clear performance improvement. Needless use of the inline keyword leads to a much bigger code size, which in turn slows down everything. Generally you should not put inline at functions with more than 4 lines of code in them.

STL

  • Use const_iterator when possible.
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox