Skip to content

Coding Standard

Jasper Drescher edited this page Nov 2, 2020 · 3 revisions

Table of contents

Introduction

The coding standard described in here outlines various guidelines for writing code. These guidelines should be adhered to as much as possible in order to submit code to the repository.

Goals

There are a few goals that we can aim for in order to keep the codebase easy to understand and maintain.

  • Consistency is key: code changes should reflect the standard.
  • Be explicit: show consideration to each other by being a bit more explicit when naming functions or variables.

Languages

C++

Code written in C++ should follow these guidelines.

Indentation should 1 Tab (4 spaces). Variable names should be prefixed with my. Variable names should use pascal case. Parameters/arguments should be prefixed with a.

Example of Foo.hpp

class Foo
{
public:
    Foo();
  
    void Update(double aDeltaTime);

private:
    int myDeltaTimeAccumulator;
};

Example of Foo.cpp

#include "Foo.hpp"

Foo::Foo()
    : myDeltaTimeAccumulator(0)
{
}

void Foo::Update(double aDeltaTime)
{
    myDeltaTimeAccumulator += aDeltaTime;
}

GLSL

Shading languages, or at least GLSL, should follow these guidelines.

Braces should be inline Indentation should be 1 Tab (4 spaces). Variables are named using camel case. Class names are named using pascal case. In and out variables should use the corresponding prefix. Uniforms should be named like local scope variables using camel case. File structure should be layout, in, out, uniform, main in that order. At the top of a shader it should declare the type and version.

Example of vertexShader.glsl

// VERTEX SHADER
#version 330

layout(location = 0) in vec3 inVertexPosition;

out VertexData {
    vec3 worldPosition;
    vec3 color;
} outVertexData;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;

void main() {
    outVertexData.worldPosition = projectionMatrix * viewMatrix * vec4(inVertexPosition, 1);
    gl_Position = outVertexData.worldPos;
    outVertexData.color = vec3(inVertexPosition.z);
}

Automation

MVS

The guidelines can be automatically applied by modifying preferences in Microsoft Visual Studio.

Clone this wiki locally