Skip to content

Code Style Guidelines

Jose Miguel de la Rosa Trevin edited this page Mar 5, 2018 · 1 revision

Consistency

We strongly believe that consistency and readability is very important when writing code and collaborating in a common project. Quoting Python PEP8:

One of Guido's key insights is that code is read much more often than it is written..."Readability counts".

A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important.

However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!

In particular: do not break backwards compatibility just to comply with this PEP!

Reference

We mostly recommend following the guidelines given here: http://geosoft.no/development/cppstyle.html

Exceptions (related to Reference)

Some exceptions are:

  • Point 31: In C++ 11, when using enum class type of of enums, there is not need to provided a common prefix the constants since enum values will be scoped: Color::RED
  • Point 34: We prefer to keep filenames (both header and source) in lower case and separated by underscore. The recommended extensions are .h for header and .cpp for source files.
  • Point 49. An addition to this point is that some complex classes with many private attributes should be implemented using the PIMPL idiom with no attributes at all except for a pointer to the implementation class defined in the source file.
  • Point 70: nullptr should be used instead of 0 and NULL in C++11.
  • Points 75-81: We prefer always the open curly brace to be on the next line and match the closing one.
  • Point 83: We prefer the return type to be in the same line of the method definition.
  • Point 85: It is not required to left a white space after the function name, neither the parenthesis.
  • Point 87: Only a single blank line should be used to methods of the same class and two lines between different classes or global methods.
  • Point 88-89: We prefer not to do special alignment, neither for variables nor conditionals.
Clone this wiki locally