Skip to content

CodingConventions

Thomas Keller edited this page Jul 28, 2020 · 3 revisions

Coding conventions

The coding conventions we use correspond to the Google c++ style guide, except for:

  • Always put the "const" keyword to the right of what is const - i.e., a const int is int const x.
  • Place the asterisk that denotes a pointer and the ampersand for a reference next to the type and not next to the variable name, i.e., write int& x and SearchEngine* search. The Google c++ style guide also allows to place * and & next to the variable name (see here, which we believe to be less intuitive as * and & describe a variables type and not its name. See the next point for an implication of this decision.
  • Do not declare two variables of the same type in one statement (e.g., int x,y). Even though this is useful sometimes, it interferes with our previous decision, as int* x, y does not declare two int pointers but one int pointer (x) and one int variable (y). The correct syntax would be int* x, * y, which violates the former exception. We do therefore not allow the declaration of multiple variables in one statement.
  • Do not overuse the auto keyword. We currently allow (and recommend) its usage in the following cases:
    • in place of iterators as, e.g. in for (auto it = myVec.begin(); it != myVec.end(); ++it) or in auto partIt = partition(...); in use cases like this, make sure to include it in your variable name
    • to declare a lambda function as, e.g., in auto hasProp = [](MyClass const& c) {return c.hasProp();};
    • in an assignment, if the type is clear and occurs on the right hand side of the assignment as, e.g., in auto c = make_shared<MyClass>()

Please note that this side is still incomplete, and that there is a large number of decisions regarding our coding style that has not even been taken yet. For instance, we aim to refactor large parts of the code by updating to C++11/14/17 (see issue #24), which is allowed in the Google c++ style guide but not enforced. However, once issue #24 is resolved, we plan on having C++11/14/17 style code mandatory where possible.

Clone this wiki locally