Changes between Version 34 and Version 35 of Coding_Conventions


Ignore:
Timestamp:
Mar 20, 2018, 9:59:45 PM (6 years ago)
Author:
Itms
Comment:

Update year and specify include order convention

Legend:

Unmodified
Added
Removed
Modified
  • Coding_Conventions

    v34 v35  
    2121{{{
    2222#!cpp
    23 /* Copyright (C) 2017 Wildfire Games.
     23/* Copyright (C) 2018 Wildfire Games.
    2424 * This file is part of 0 A.D.
    2525 *
     
    3838 */
    3939}}}
    40    replacing `2017` with the year that the file was last updated.
     40   replacing `2018` with the year that the file was last updated.
    4141
    4242  '' Exception:''  Code in `source/lib/`  (and a few other files) should use the MIT license instead:
    4343{{{
    4444#!cpp
    45 /* Copyright (C) 2017 Wildfire Games.
     45/* Copyright (C) 2018 Wildfire Games.
    4646 *
    4747 * Permission is hereby granted, free of charge, to any person obtaining
     
    7777 * All source files must have the `svn:eol-style` property set to `native`
    7878
    79  * The first non-comment line of any source file must be `#include "precompiled.h"`
    80 
    8179=== Formatting ===
    8280 * Use tabs for indentation, not spaces.
     
    208206}}}
    209207
     208=== Preprocessor instructions ===
     209
     210The `#include` instructions, placed after the license notice, should follow a consistent order (which is currently not the case). Between each section in the following list, we usually add an empty line.
     211
     2121. The first non-comment line of **any** source file **must** be `#include "precompiled.h"`
     2131. For `.cpp` files that contain function implementations, headers that declare those functions should be included here. For instance, `#include "Simulation2.h"` for `Simulation2.cpp`, or `#include "ICmpPosition.h"` for `CCmpPosition.cpp`.
     2141. Include the files that come from the same folder. Do not write the complete path relative to `source/`, but rather the file name only. Use case-insensitive alphabetical order.
     2151. Include the files that come from the same project, but a different folder (even subdirectories of the current file's directory). Write the complete path relative to `source/`, for instance `#include "simulation2/Simulation2.h"`. Use case-insensitive alphabetical order.
     2161. Include the files that come from other projects. Write the complete path relative to `source/`, for instance `#include "lib/file/file.h"`. Use case-insensitive alphabetical order.
     2171. Include system libraries, in case-insensitive alphabetical order.
     218
     219Example, for the file `source/simulation2/Simulation2.cpp` (this is not the actual list, but an example that should cover all cases):
     220
     221{{{
     222#include "precompiled.h"
     223
     224#include "Simulation2.h"
     225
     226#include "Example.h"
     227#include "MessageTypes.h"
     228
     229#include "simulation2/components/ICmpAIManager.h"
     230#include "simulation2/components/ICmpCommandQueue.h"
     231#include "simulation2/components/ICmpTemplateManager.h"
     232#include "simulation2/system/ComponentManager.h"
     233#include "simulation2/system/ParamNode.h"
     234
     235#include "graphics/Terrain.h"
     236#include "lib/file/vfs/vfs_util.h"
     237#include "lib/timer.h"
     238#include "maths/MathUtil.h"
     239#include "ps/Loader.h"
     240#include "ps/lowercase.h"
     241#include "ps/Profile.h"
     242#include "ps/XML/Xeromyces.h"
     243#include "scriptinterface/ScriptInterface.h"
     244#include "scriptinterface/ScriptRuntime.h"
     245
     246#include <iomanip>
     247#include <string>
     248}}}
     249
    210250=== Misc ===
    211251 * In header files, avoid `#include` and use forward declarations wherever possible.
    212 
    213  * Sometimes it's nice to put `#include`s in alphabetical order. (It's a bit prettier, and makes it easier to find if some header is already in the list or not.) (But when `Foo.cpp` includes `Foo.h`, that should usually go before every other include (except for `precompiled.h` which must always be first).)
    214252
    215253 * Class names are !UpperCamelCase and prefixed with `C`, e.g. `CGameObject`. Member functions are !UpperCamelCase, e.g. `CGameObject::SetModifiedFlag(...)`. Member variables are !UpperCamelCase prefixed with `m_`, e.g. `CGameObject::m_ModifiedFlag`. Files are named e.g. `GameObject.cpp`, `GameObject.h`, usually with one major class per file (possibly with some other support classes in the same files). Local variables and function parameters are lowerCamelCase. Structs are treated similarly to classes but prefixed with `S`, e.g. `SOverlayLine`.