Skip to content

Coding Standard

liljekvist edited this page Dec 2, 2021 · 3 revisions

Coding standard

C++

Naming scheme

variablesLikeThis
FunctionsLikeThis()
ClassesLikeThis

Brackets

Functions, overloads and classes

{} on next row

ex

void f(const std::vector<double>& v)
{
  std::cout << "Values:";
  for (auto value : v)
    std::cout << ' ' << value;
  std::cout << '\n';
}

Fred operator+ (const Fred& a, const Fred& b)
{
  Fred ans = a;
  ans += b;
  return ans;
}

Multiline if statements / for loops

ex

if (true) {
  ExampleIf();
}

for (auto example : cheatSheet) {
  std::cout << example << std::endl;
}

Use Const as default

Const correctness is important.

Avoid enum and use enum class

More safety is always good

Clone this wiki locally