Skip to content

Coding guide naming

Péter Kardos edited this page Jan 28, 2018 · 7 revisions

Code style

The engine follows the code styling described on this page. Examples can be found in core file of the graphics engine, such as Scheduler, Pipeline, Command lists, Binder, Memory management.
These rules apply to C++ sources as well as shaders.

Naming

  • Variables: camelCase
  • Functions: PascalCase
  • Class Members: m_camelCase
  • POD Struct Members: camelCase
  • Member Funcions: PascalCase
  • Enums: ePascalCase
  • Enum Constants: ALL_CAPS
  • File Names: CamelCase.hpp/.cpp/.hlsl
  • template non-type arg: template
  • template type arg: template <class T/U/T1/T2/Type/TypeT> depending on what fits
  • constexpr: ALL_CAPS if publicly exposed, your choice if internal only

Indentation

  • 1 tab per indent
  • Set tabs to 4 spaces
  • Mix tabs & spaces for fine alignment
  • Opening braces same line
  • Don't be retard

Member ordering

class C {  
    // private typedefs, classes, constexprs, friends, etc.  
public:  
    // constructor -> operator= -> indexers -> public interface  
protected:  
    // protected member functions  
protected:  
    // protected member variables  
private:  
    // funtcions  
private:  
    // variables  
};  

Includes

  • Externals and module root directory added to include path
  • Files of the same module #include each-other via ""
  • Externals, files of another module and system headers are #included via <> Example:
[#pragma once] // use pragma once for headers, NO ifdef include guards

// first include current module's files
#include "GraphicsCommandList.hpp"
#include "Misc/Utility.hpp"
#include "Nodes\Node_GetTime.hpp" // BACKSLASH FORBIDDEN (set VS to prefer fw slash)

// then other modules' files
#include <GraphicsApi/IGraphicsApi.hpp>
#include <BaseLibrary/Any.hpp>
#include "BaseLibrary/SmartPtrCast.hpp" // QUOTATION MARKS FORBIDDEN FOR IN-PATH INCLUDES

// and finally system headers
#include <cmath>
#include <Bullet/RigidBody.hpp>

The order of includes is important. First, consistency never hurt anyone, second, it will show when local files forgot to include foreign module and system headers they need.

Namespaces

  • Everything inside "inl"
  • Namespace for each module: e.g. inl::gxeng, inl::gxapi
  • Maths in "inl" directly

Documentation
XML Doc comments: /// <tag> Text </tag>
Recommended tags: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/recommended-tags-for-documentation-comments

Clone this wiki locally