Skip to content

Style Guide

Qais Patankar edited this page Feb 29, 2020 · 3 revisions
  • We use 4 spaces instead of tabs.

  • Hungarian notation for variable names.

    float         fValue;               // Local variable
    unsigned char m_ucValue;            // Class member variable
    char          ms_cValue;            // Class static variable
    bool          g_bCrashTwiceAnHour;  // Global variable
    char*         szUsername;           // Zero terminated string
    SString       strUsername;          // String
    CVector       vecPosition;          // 3D Vector
  • Lower camel case for variable names of types like custom structs and enums:

    SSomeStruct   valueOne;
    ESomeEnum     m_valueTwo;
  • Function names use UpperCamelCase:

    void UpperCamelCase()
  • Functions with no arguments are declared and defined with (), and called with ()

    void MyTest();
    void MyTest() { return; }
    MyTest();
  • Do not use nested structures without braces:

    // This is disallowed:
    for (dont)
        for (do)
            for (this)
                ...
    
    // Either of these are allowed
    if (x) {
        y;
    }
    
    if (x)
        y;
  • Put #pragma once preprocessor directive next to the copyright comment for new header files and the ones you are modifying for the pull request. Make sure to remove include guard if you are using #pragma once:

    /*****************************************************************************
    \
    *
    *  PROJECT:     Multi Theft Auto
    *  LICENSE:     See LICENSE in the top level directory
    *  FILE:        Client/mods/deathmatch/logic/CClientIFP.h
    *
    *  Multi Theft Auto is available from http://www.multitheftauto.com/
    *
    *****************************************************************************/
    
    #pragma once
  • Once you're done writing code, and you're about to create a pull request, apply clang formatting:

  • For anything else, follow the style of the code that already exists.

  • Tip: In Visual Studio go to Tools -> Options -> Text Editor -> C/C++ -> Formatting -> Spacing and you can configure it to automatically apply the right spacing.

Clone this wiki locally