Code Formatting Conventions

In the beginning of OpenMW we did not have any code formatting conventions, which resulted in substantial inconsistencies. This page tries to codify the conventions that are most commonly used in the code base. Please stick to them, even if the code in the neighbourhood of what you are working on is not.

Layout &amp; Indention
This is an example of the layout &amp; indention style we encourage.

Note that the indention width is 4 spaces. If you use tabs instead of spaces, our build server will reject your code. Mixing spaces and tabs is not good.

Includes
An implementation file (cpp) should always start by including its own header.

Further includes should be grouped. Groups must be separated by an empty line.

Standard C and C++ headers
Example:

C headers (if any) should be listed before the C++ headers.

External libraries headers
If more than one external library is used, each library's headers should be put into a separate group.

Doxygen Comments
Class definitions and function declarations should have doxygen comments. We aren't very strict about this though (especially for trivial functions).

A class should be documented like this:

The longer description can be skipped, if there is nothing more to say.

A function should be documented like this:

Here is a link to the Doxygen Documentation. Please make plenty of use of the listed commands, especially the following:


 * \a
 * \attention
 * \brief
 * \note
 * \p
 * \param
 * \return
 * \todo