diff --git a/docs/cpp-code-standards.md b/docs/cpp-code-standards.md index 28e4c084..fe93ffe8 100644 --- a/docs/cpp-code-standards.md +++ b/docs/cpp-code-standards.md @@ -53,7 +53,7 @@ if (a == b) Trailing whitespace is not allowed. -You should also not have unneeded spaces within a bracket. +You should also not have unneeded spaces within a bracket. Wrong: @@ -330,6 +330,36 @@ All Header files should contain header guards #endif // MY_HEADER_H ``` +### Includes + +Every header must be **self-contained**: it must compile on its own, without depending on other headers being included before it. This prevents hidden fragile dependencies. If "A" needs "B" and "C", it should include "B" & "C". It shouldn't only include "B", just because "B" happened to include "C" right now. "A" should also not include anything it doesn't directly use. + +Includes are written as a single block with no blank lines inside it, ordered as follows: + +1. The file's own header first in the .cpp (if the .cpp needs to include its own header). +2. All other project headers, in alphabetical order. +3. All library headers, in alphabetical order. + +ItemEnchantmentMgr.cpp example: + +```cpp +#include "ItemEnchantmentMgr.h" // The file's own header, first +#include "DBCStores.h" // then project headers, alphabetically +#include "DatabaseEnv.h" +#include "Log.h" +#include "ObjectMgr.h" +#include "QueryResult.h" +#include "Timer.h" +#include "Util.h" +#include // then library headers, alphabetically +#include +#include +``` + +Alphabetical ordering is case-sensitive (ASCII order, matching clang-format's default): uppercase letters sort before lowercase. Above, `DBCStores.h` precedes `DatabaseEnv.h` because the uppercase `B` sorts before the lowercase `a`. + +Project headers use quotes (`"..."`); library headers (C++ standard library, boost, etc.) use angle brackets (`<...>`). A third-party library bundled into the codebase, such as G3D, is the exception and uses quotes. + ### Text Output All C++ script/system/command text output must use [acore_string](acore_string) whenever possible (e.g., ChatHandler messages, script system messages).