Coding guidelines

From VDrift
Revision as of 10:53, 25 February 2007 by 67.183.220.122 (talk) (→‎Code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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.

Code

VDrift code is formatted using all tabs and no spaces. The following example demonstrates VDrift's coding style.

class EXAMPLECLASS
{
private:
        int data;

public:
        EXAMPLECLASS();
        ~EXAMPLECLASS(); 

        void MemberFunction();
};

// Add the sum of the number 1 - 10 to data.
void EXAMPLECLASS::MemberFunction()
{
        // loop and add i to data  <-- Useless comment, should be avoided.
        for (int i = 1; i <= 10; i++)
        {
                data += i;
        }
}

Indentation and Naming

Notice the use of ALL CAPS for class names. Function names should be presented in MixedCase?. Opening and closing curly brackets ({}) should be on their own line, and should not be indented. The enclosed statements however, should be indented.

Control statements should have one space between the statement and the left paren. There should be no padding inside of the parens unless it helps readability, use your judgement. Function calls should have no spaces between the function name and the left paren. Commenting

Do not over use comments. Only comment code that has side effects, is not clear at first glance, or that does complex operations. It is ok to comment a section of code with a comment describing what that section does.

Note: Currently, not all of VDrift's code follows these guidelines, do not waste time cleaning up the code, unless you are re-writing that particular piece of it. There will be a time when the code will be cleaned up. Also code from the Vamos project, does not follow these guidelines either. Make sure all new code written for VDrift follows these guidelines.