-
-
Notifications
You must be signed in to change notification settings - Fork 437
Style Guide
-
We use 4 spaces instead of tabs.
-
Hungarian notation for variable names. (Although, not enforced for new code)
float fValue; // Local variable unsigned char m_ucValue; // Class member variable char ms_cValue; // Class static member variable bool g_bCrashTwiceAnHour; // Global variable char* szUsername; // Zero terminated string SString strUsername; // String CVector vecPosition; // 3D Vector
Sometimes
a
is used for arrays C-style arrays. -
Lower camel case for variable names of types like custom structs and enums:
SSomeStruct valueOne; ESomeEnum m_valueTwo;
-
Functions and classes use UpperCamelCase:
void UpperCamelCase(); class Vector;
-
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;
-
Use range-based for loops wherever possible (all std containers support it):
std::vector<int> vec; // Example std container // Bad: for (std::vector<int>::iterator it = vec.begin(); it != vec.end(); it++) // Good: for (const auto& v : vec) for (const int& v : vec) // In case of maps you can use structured binding: std::map<std::string, int> myMap; for (const auto& [k, v] : myMap) // There are situations where you must use old style loops, in this case use `auto` for (auto it = vec.begin(); it != vec.end(); it++)
-
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:
- Download clang-format-r325576.exe, and move it to utils folder.
- Download fnr.zip, extract fnr.exe to utils folder.
- Run
utils/win-apply-clang-format.bat
-
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.
Project Management
Git cheat sheet
Release Checklist
Code Review
Documentation
Contributors Guide
Style Guide
Lua API
Dev Tips
BitStream
CAccountPassword
Debug Settings
General
Testing Lua
Dependencies
MTADiag
Future Planning
CEF Versions
Windows XP Support
Things for 1.6