Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Style guide should be followed for all C++ code developed for WARG.

Can I propose a few changes (following what gordon said). Basically this changes variables to snake case and classes to PascalCase?

for example:

Variables

...

Spacing

We use tabs here.

Variables

Note: For class and struct member conventions, refer to the Data Structures section.

All variables must follow snake case.

Code Block
languagecpp
int you_are_reading_this = 0;
int you_are_reading_thingsthis{0}; \\ what
about like this
bool nice_thanks_for_reading = false;
bool nice_thank_youthanks_for_reading{false}; \\ and
like this
double this_is_super_fun = 0.0f;

Static variables in classes are prelined by an underscore before the first character.

Code Block
languagecpp
int _this_is_a_static_variable = 0;
bool _do_you_understand = false;
double _ok_keep_reading = 0.0f;

Variables

All variables must follow lower Camel Case.

Code Block
languagecpp
int youAreReadingThis = 0;
bool niceThanksForReading = false;
double thisIsSuperFun = 0.0f;

As a rule of thumb, all variables should be initialized upon declaration to prevent undefined behaviour.

...

Code Block
languagecpp
// These are static variables for a class
static int _youAreReadingThisyou_are_reading_this{0};
static bool _niceThanksForReading;_nice_thanks_for_reading = false;
static double _thisIsSuperFun_this_is_super_fun = 0.0f;

Constants

Constants (const and constexpr) should be named using camel case, with the first character being a k:

Code Block
const int kYouAreReadingThis{0}
constexpr bool kNiceThanksForReading{false};

Pointers

The * should be separated on both sides by a space:

Code Block
languagecpp
int * integerPointerinteger_pointer = nullptr;

As a rule of thumb, all pointers must be initialized on declaration. If you are not assigning it a value, then set it to nullptr like the example above.

...

There should always be spaces around all mathematical operators (except division). There should always be spaces between equal signs.

Code Block
languagecpp
int b = (1 + 2 - 3) * randomVariablerandom_variable / 5.0 + randomVariableTworandom_variable_two % 7;

Selection

Conditions

Operations

...

Code Block
languagecpp
int a = 1;
switch(a) {
  case 1: // Indent the cases 
    ... 
    break;
            // Keep a space between the end of one case and the condition of the next 
  case 2:
  case 3:
    ... 
    break;
    
  default: // Always include a default case
    break;
}

Loops

Curly Brackets

Should be on the same line as the do, for, and while keyword:

Code Block
for ( ... ) {
}

do {
} while ( ... );

while {
} 

Also keep a space between the do, for, and while keyword; conditions, and open curly-bracket.

Conditions follow same rules as if statements.

Breaks

We try to avoid using the break keyword when exiting loops. Instead, use a boolean flag to track if the loop is done executing.

Code Block
bool isDone{false};
for (int i = 0; i < 10 && !isDone; i++) {
  if (6 == i) {
    isDone = true;
  }
}

Functions

Naming and Brackets

...

Code Block
int hewwoThereFwend() { 
  return 0; 
}

Parameters

Parameter names

Parameter names should be in camel case

Pointers

The * in pointers must be separated on both sides by one space.

...