Changes between Version 56 and Version 57 of Coding_Conventions


Ignore:
Timestamp:
Aug 17, 2022, 9:01:56 PM (21 months ago)
Author:
Vladislav Belov
Comment:

Reverted to version 55.

Legend:

Unmodified
Added
Removed
Modified
  • Coding_Conventions

    v56 v57  
    2202201. 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`.
    2212211. Include the rest of the files that come from 0 A.D. Write the complete path relative to `source/`, for instance `#include "simulation2/Simulation2.h"`. Use case-insensitive alphabetical order.
    222 1. Include system libraries and third party libraries, in case-insensitive alphabetical order.
     2221. Include system libraries, in case-insensitive alphabetical order.
    223223
    224224Example, for the file `source/simulation2/Simulation2.cpp` (this is not the actual list, but an example that should cover all cases):
     
    247247
    248248#include <iomanip>
    249 #include <boost/optional.hpp>
    250249#include <string>
    251250}}}
     
    268267}}}
    269268
    270  * [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-lib Prefer the standard library to other libraries and to “handcrafted code”]
     269 * Use STL when appropriate.
    271270
    272271 * Don't use RTTI (`dynamic_cast` etc). ''Exception:'' `source/tools/atlas/AtlasUI/` can use RTTI.
     
    277276   * Prefer global variables over singletons, because then they're not trying to hide their ugliness.
    278277
    279  * Use `nullptr` for pointers (instead of `NULL`). This convention should be implicit but stated hear because there are still many places were `NULL` is used.
     278 * Use `nullptr` for pointers (instead of `NULL`).
     279
     280 * Don't do "`if (p) delete p;`". (That's redundant since "`delete nullptr;`" is safe and does nothing.)
    280281
    281282 * If deleting a pointer, and it's not in a destructor, and it's not being immediately assigned a new value, use "`SAFE_DELETE(p)`" (which is equivalent to "`delete p; p = nullptr;`") to avoid dangling pointers to deleted memory.
    282283
    283  * A loop should not be "controled" by the body:
    284    * don't use `break` or `return` statements.
    285    * don't mutate the iterator variable. Can be enforced by using range-based for loops.
    286 {{{
    287 #!cpp
    288 // Bad
    289 for (size_t i = 0; i != 6; ++i)
    290 {
    291     // This loop never ends
    292     ++i;
    293 }
    294 // God
    295 for (const auto i : std::ranges::iota(0, 6))
    296 {
    297     ++i; //compile-time error;
     284 * Be sure to be aware of [CodeAndMemoryPerformance Code And Memory Performance] guidelines
     285
     286 * Use "for range" loop instead of "std::for_each".
     287{{{
     288#!cpp
     289// Avoid
     290std::vector<T> anyVector;
     291std::for_each(anyVector.begin(), anyVector.end(), [] (const T& element){
     292   // code
     293}
     294
     295// Better
     296for (const T& element : anyVector)
     297{
     298   // code
    298299}
    299300}}}
     
    312313}}}
    313314
    314  * [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-auto Use `auto` to avoid redundant repetition of type names.] Be aware that overuse of `auto` can also cause problems in the long-run.
     315 * In `c++11`, it is possible to use the `auto` type-specifier, wherein the appropriate data-type is determined at compile time. Although potentially useful, overuse can cause serious problems in the long-run. Therefore, this code feature should be used in moderation. Specifically:
     316   - It should be clear from reading the code what type the `auto` is replacing. (Add a comment if necessary.)
     317   - It should only ever be used as a replacement for an iterator type.
     318   - It should only be used if the data-type-specifier it is standing in for is long. As a rule of thumb, if the line would be shorter than your chosen suitable line width (see convention on avoiding wide lines under [#Formatting formatting] above) without it, don't use it.
    315319
    316320 * Favour early returns where possible. The following:
     
    336340}
    337341}}}
    338 
    339  * Be sure to be aware of [CodeAndMemoryPerformance Code And Memory Performance] guidelines
    340 
    341  * There aro also the [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines C++ Core Guidelines]
    342342
    343343