Wartbed:Code style

From Dark Omen Wiki

(Difference between revisions)
Jump to: navigation, search

Mikademus (Talk | contribs)
(New page: <div style="float:right; margin-left:1em;"> __TOC__ </div> {| |- style="vertical-align:top;" |'''Note:''' | ''This page isn't something most people are interested in. I am writing and ma...)
Newer edit →

Revision as of 22:10, 18 February 2009

Contents

Note: This page isn't something most people are interested in. I am writing and maintaining it more as a guide to myself to help me with coding consistency. Some parts of WARTBED consists of code predating this Standard and may thus deviate from it. If parties interested in assisting with WARTBED feel dissuaded for aesthetics reasons due to this Standard then remember the golden rule: "Ignore all rules to achieve the best possible result".


Naming conventions

  • All classes and functions are captialised. All class members or any global variables are initiated by lower-case.
  • Genrally, CamelCase is used to separate words in identifiers. There are exceptions where appropriate and for better adherence to STL naming conventions.
  • Typedef and enumeration identifiers are upper-cased. Enumeration members need not be upper-cased but are always initiated by a common word in upper case.
template<typename T>
class Regiment
{
    void member() {}
    int  anotherMethod() {}   
};

typedef Regiment<int> REGIMENT;

enum ORDER
{
    ORDER_approach,
    ORDER_retreat,
};


Calling conventions

  • References are preferred over pointers
  • Const is preferred over non-const
  • The "const" keyword is placed after the data type.


Horizontal indentation

  • All tabs are translated to space. Tab with is set to 4 spaces.
  • All brackets are set on their own lines, except where silly or better aesthetics is achieved otherwise. Brackets are set on their own lines and underneath the first character of their owning keyword. This includes classes, scopes, flow control structures and namespace declarations.
  • Switch/case-structures use indented case clauses, generally with code bodies underneath the case and indented one additional step.
  • Function signatures and calls are padded with one space.
  • Flow control parameters (if, for, while etc) are indented one space from their keyword and use no internal padding.
namespace wb
{
    class Weapon
    {
    };

    void Function( std::string const &rStr )
    {
        AnotherFunc( rStr );

        for (unsigned i = 0; 1 < rStr.length(); ++i)
        {
        }
    }
}


Comments and vertical spacing

  • Block comments are dissuaded in the main code since they interfere with temporary commenting out large blocks of code.
  • Temporary commenting out of lines generally place the comment token at column 0 of the line.
  • Class and function names are emphasised by a leading and following comment dash-line. Non-documentation (/** ... */ or /// comments) descriptions are placed underneath the first dash-line. While this might look a bit uncommon, it has proven to be highly useful for good code block separation and object identification.
  • Separate code blocks (classes, functions) are separated by three linefeeds.
  • Internal structure in code is maintained by liberal usage of blank lines.
/*******************************************************************
 * Source file.cpp                                                 *
 * Copyright notice and documentation                              *
 *                                                                 *
 *******************************************************************/

namespace wb
{
//------------------------------------------------------------------
    class Weapon
//------------------------------------------------------------------
    {
    };



//------------------------------------------------------------------
// SpecialWeapon is a specialisation of Weapon. It adds 
// many special capabilities over Weapon.
//
    class SpecialWeapon
//------------------------------------------------------------------
    {
    };



//------------------------------------------------------------------
    void Function( std::string const &rStr )
//------------------------------------------------------------------
    {
        AnotherFunc( rStr );

        for (unsigned i = 0; 1 < rStr.length(); ++i)
        {
        }
    }
}
Personal tools
communication