Newer
Older
GameEngine / src / StyleGuide.md
@John Ryland John Ryland on 22 Aug 2 KB save WIP

// For all class names, function names, variable names, avoid using abbreviations and use // American English spelling. Exceptions can be made for local variables of limited scope. // Function names should be limited to no more than 4 words combined to form the function name.

// Function names and classes are camel case with first character upper case, eg:

class MyClass;

void MyFunction();

// Member functions are the same. Avoid repeating the class name in the function name, eg:

namespace Vulkan {

class Shader { public: // don't void CreateVulkanShader();

// don't
voic CreateShader();

// do
voic Create();

};

}

// Parameters to functions should be camel case but start with a lower first character, eg:

void MyFunction(bool enableDebug, const char* resourceFileName);

// Member variables should be prefixed with 'm' or 'm_', eg:

class MyClass { // prefer: int m_count; // or int mCount; // avoid int m_Count; }

// Global variables should be avoided, however prefix with 'g' or 'g_', eg:

// prefer: int g_debugEnabled; // or int gDebugEnabled;

// Local variables shouldn't be camel case, instead split with '_'s, eg:

void MyFunction() { int debug_enabled; }

// defines and macros should be avoided but if used should be all upper case, eg:

#define ARRAY_SIZE(array) std::size(array)

// follow this formatting of the member initialization in constructors

Buffer::Buffer(Device& device, size_t size, int usage) : m_owner(device) , m_size(size) , m_usage(usage) {

// When the line for a function is too long, split it like this

// Change this ImageBuffer::ImageBuffer(Device& device, uint32_t width, uint32_t height, Format imageFormat, uint8_t mipLevels, uint8_t samples) : m_device(device) , m_width(width) // ... { }

// to this:

ImageBuffer::ImageBuffer(Device& device, uint32_t width, uint32_t height, Format imageFormat, uint8_t mipLevels, uint8_t samples) : m_device(device) , m_width(width) // ... { }

// Example of disabling compiler specific warnings

// Visual Studio warnings

#ifdef _MSC_VER

#pragma warning (disable: 4127) // condition expression is constant

#endif

// Example usage of namespace, note the comment on the closing brace

namespace ApplicationFramework {

// Code here

} // ApplicationFramework namespace

// Avoid hardcoded numbers/values inside of code blocks, prefer to move these as const // values at the beginning of file/class/function, eg:

// don't void zoom(float& x, float& y) { x = 2.0f; y = 2.0f; }

// do static const float s_zoomFactor = 2.0f;

void zoom(float& x, float& y) { x = s_zoomFactor; y = s_zoomFactor; }