Skip to content

Latest commit

 

History

History
79 lines (69 loc) · 1.63 KB

cpp.md

File metadata and controls

79 lines (69 loc) · 1.63 KB

C++ Style Guide

Table of contents:

  1. Naming
    1. Variable names
    2. Function names
    3. Constants
    4. Type names
    5. File names
  2. Formatting
    1. Curly brackets location
    2. Spaces vs. Tabs
    3. Line length
    4. Operator spacing
    5. Pointers declaration

Naming

Variable names

For variables, we use camelCase:

int gold;
int healthPoints;
string reallyLongVariableNameM8;
string datBoi;  // o shit waddup
// etc...

Function names

Like a variable: camelCase:

bool toBeOrNotToBe();
int getQuantityOfDeadMemes();

Constants

All uppercase with underscores:

const int WINDOW_WIDTH = 640, WINDOW_HEIGHT = 480;
const int DAYS_IN_A_WEEK = 7;

Type names

For type names we use Pascal case:

class MyNewClass;
struct Vector2f;
enum CharacterClass;
// etc...

File names

Filenames should be all lowercase and can include underscores:

foo_bar.cpp

Formatting

Curly brackets location

We use curly brackets as following (this applies to loops, switch statements and functions as well):

if() {
    // ...
}

Spaces vs. Tabs

Tabs for indentation (4 spaces width), spaces for aligning.

Line length

Keep the line length 120 characters max.

Operator spacing

We use spacing for all operators excluding the following: (), ;

Pointers declaration

Space on right side of * operator like this:

char* thePointer;