House style

This course uses a house-style!

All codes in this course are expected to have been written using ourhouse style, which will try to follow the C++ core guidelines as closely as possible (or at least, the easier sections while we are building up your confidence). Another rather different set commonly used is the google C++ style. If you are to become a professional coder–and quite a few studentstaking this course do–one of the important prerequistes you will be expected to stick to is a house style: that makes it easier for you to know what is right and wrong, and for us to explain the marks!

Variables and comments

Let me highlight a few parts of section NL here:

  • Variable naming: Variable and function names must describe in detail the meaning and function (but not the type) of a variable, e.g. speed_of_light_in_vacuum
  • Naming Style: We have decided to use all lowercase, see NL.8 (unless you use a proper name) hyphenated variable and function names, e.g., speed_of_light_in_vacuum and calculate_tax().
  • Comments
    • NL.1: Don’t say in comments what can be clearly stated in code
    • NL.2: State intent in comments
    • NL.3: Keep comments crisp
    • NL.15: Use spaces sparingly
    • Etc.

Curly braces {} and indentation

We will use curly braces in a "medium compact" notation where an opening brace occurs on the same line as the statement it follows, apart from the case of a function or a class, where we shall put it on a new line. If the next statement after the closing brace is part of the same expression (as in the case of, e.g. an else) this will be on the same line as a closing brace. Statements will be rigourously indented, i.e., each nested block will indent the same number of spaces (see NL.4).

Namespaces

We normally will use a namespace by the name resolution operator,e.g., std::cout<<i; and not using namespace std;cout <<i; The reason for this will become clear when we discuss namespaces in detail, but see SF.6.

Further development

When introducing new concepts, we shall attempt to introduce the relevant parts of the housestyle (again, by highlighting the relevant section of the style guide)