Coding style

From Code::Blocks
Revision as of 12:06, 14 December 2005 by Mandrav (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

NOTE: this is yet unfinished

The following are guidelines for the code formatting to use in Code::Blocks (C::B) source code. Anyone writing code or a patch for C::B, is required to follow these.

The general coding style is the ANSI one:

Example:

namespace FooSpace
{
    int Foo()
    {
        if (isBar)
        {
            Bar();
            return 1;
        }
        else
            return 0;
    }
}


Variables naming

Non-class member variables should use capital letter at the start of each word, except for the first.

Class member variables should start with m_. If the variable is a pointer, use m_p as a prefix. Following the prefix is the variable's name. Use descriptive names and use capital letters at the start of each word (the first too). So a fictious variable holding a value for position would be named as m_ValueForPosition.

Examples:

// Good
int aLocalVar;
int m_SomeInt;
void* m_pSomePointer;

// Bad
int SomeInt; // either no m_ prefix if it's a class variable, or capital first letter if it's a local variable
int m_someInt; // no capital letter 'S'
void* m_SomePointer; // no m_p prefix


Variables declaration

One variable declared each time on a different line. For pointer/reference variables, put the * or & right after the type not before the variable name.

Examples:

// Good
int& someInt;
void* pPtr;

// Bad
int &someInt; // & not after type
void* pPtr, pSomeOther; // multiple declarations in one line