GAMMA E., HELM R., JOHNSON R., VLISSIDES J. M.: Design Patterns: Elements of Reusable Object-oriented Software, 1st Edition, Addison-Wesley Longman Publishing Co., 1995.
GREGORY J.: Game Engine Architecture, 2nd Edition, A K Peters/CRC Press, 2014.
KARPOV A.: The Ultimate Question of Programming, Refactoring, and Everything, 2016.
KAYARI: C++ Antipatterns, s.d.
MEYERS S.: Effective C++, 3th Edition, Addison-Wesley Professional, 2005.
MEYERS S.: Effective Modern C++, 1st Edition, O'Reilly Media, 2004.
STROUSTRUP B., SUTTER H.: C++ Core Guidelines, 2018.
Prefer the type definitions/aliases (utils\type\types.hpp
) and std::size_t
over non-typedefed built-in types.
- Always use
const
(member method, method return argument, method input arguments, local variables) if applicable. - Always use
const
for return by value of non-built-in types to avoid assignment (and its side effects). C++17's Guaranteed Copy Elision will avoid invoking the copy constructor or copy assignment operator.
Put all constructors and destructors of non-template base and child classes in the .cpp
file.
Prefer explicit
(non-default, non-copy, non-move) constructors (independent of the number of arguments).
Prefer inheritance with explicit
child constructors over type definitions/aliases to force explicit type conversion between aliases.
Do not use implicitly defined (i.e. compiler generated) member methods. Always declare and define (with = default
/= delete
if possible) the following member methods:
- Default constructor (if and only if this is the only constructor in the
class
/struct
) - Destructor
- Copy and move constructor
- Copy and move assignment operator
Note that Move Constructors make sense in nearly all situations. So prefer = default
over = delete
.
Give deleted member methods the access modifier you would (hypothetically) give them if they would not be deleted:
- Copy and move assignment operators will be
public
in concrete and abstract classes for most cases. - Copy and move constructors will be
public
in concrete classes for most cases. - Copy and move constructors will be
protected
in abstract classes for most cases. - Copy and move constructors will be
private
in concretefinal
classes that can only be instantiated byfriends
for most cases.
In all cases, an announcement is made to the appropriate users of a class instead of all users of a class.
Enumerate all member variables in the initializer list of constructors in order.
- Do not use
new
,new[]
,delete
,delete[]
. - Use
MakeUnique
for assigning toUniquePtr
. - Use
MakeShared
for assigning toSharedPtr
in case the data does not require custom allocaters. - Use
MakeAllocatedShared
for assigning toSharedPtr
in case the data requires custom allocaters and/or deallocation needs to happen as early as possible.
- Use
SharedPtr
,UniquePtr
andComPtr
(memory\memory.hpp
) to express ownership. - Use
WeakPtr
(forSharedPtr
), raw pointer (forUniquePtr
andComPtr
) to express usage without ownership.
Always use static_cast
for type conversion between built-in types (as opposed to C style casts).
Do not use ZeroMemory
, use = {}
instead. (Though, SecureZeroMemory
may be used).
- Use
.hpp
for C++ header files. - Use
.tpp
for C++ header files containing template definitions. - Use
.cpp
for C++ source files. - Use
.hlsl
for HLSL shader files. - Use
.hlsli
for HLSL non-shader files.
Lines have a maximum width of 80 characters.
- Use lowercase names for namespaces.
- Use lowercase names with
_
delimiters for variables. - Use upper camal case a.k.a. Pascal case names for classes, ((class) member) methods and (class) types.
- Exceptions are allowed for STD/STL compliance.
Remove trailing spaces (Visual Studio regex: [^\S\r\n]+(?=\r?$)
)
- Use the prefix
g_
for global variables (C++ and HLSL). - Use the prefix
m_
for member variables (C++ and HLSL). - Use the prefix
s_
for class and method member variables (C++ and HLSL).
Use Yoda conditions to avoid accidental variable assignments within conditionals.
- Codacy
- PVS-Studio Analyzer (stand-alone or Visual Studio plugin)
- Visual Studio 2019
Copyright © 2016-2024 Matthias Moulin. All Rights Reserved.