Differences between revisions 6 and 7
Revision 6 as of 2010-09-03 16:51:17
Size: 2278
Editor: MalteHelmert
Revision 7 as of 2010-10-31 16:04:48
Size: 2307
Editor: MalteHelmert
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:

== C++ code ==
Line 10: Line 12:
 * [[/Formatting]]: line length, how to break lines, where to put spaces, etc.  * [[/C++Formatting]]: line length, how to break lines, where to put spaces, etc.
Line 12: Line 14:
== General recommendations == === General recommendations ===
Line 20: Line 22:
== Namespaces == === Namespaces ===
Line 27: Line 29:
== Header file guards == === Header file guards ===
Line 47: Line 49:
== Function signatures == === Function signatures ===

Back to the HomePage.

Coding conventions

C++ code

This is not meant to be a complete description of our coding conventions. When in doubt, follow the example of the existing code.

To keep the size of this file reasonable, the following parts have been broken out to subpages:

  • /C++Formatting: line length, how to break lines, where to put spaces, etc.

General recommendations

We generally follow the recommendations in the book C++ Coding Standards: 101 Rules, Guidelines, and Best Practices by Herb Sutter and Andrei Alexandrescu. In the tracker or elsewhere, a mark of the form [SA x] is a reference to a rule in that book. For example, [SA 9] refers to Sutter and Alexandrescu's rule 9: "Don’t pessimize prematurely".


  • Every subdirectory should correspond to a namespace.
  • Avoid nested namespaces or subdirectories of subdirectories.
  • Namespaces follow the same camel-case naming convention as classes, while directory names follow the naming conventions for methods and variables. For example, file my_subdir/my_class.h would be expected to contain a definition of class MySubdir::MyClass.

  • Namespaces should have short, single-word names if possible. (The previous example only uses an underscore in the subdirectory name for sake of illustration.)

Header file guards

Macro names for header file guards follow this algorithm:

  • Take the filename, including subdirectory name if in a subdirectory.
  • Convert to uppercase.
  • Replace all "." and "/" with "_".

Example: learning/state_space_sample.h becomes LEARNING_STATE_SPACE_SAMPLE_H.

Guard blocks should look like this:

   3 // ...
   4 #endif

That's all. In particular, don't add comments to the preprocessor directives and don't add further underscores.

Function signatures

  • Use const methods whenever appropriate.

  • Pass strings by const reference.

  • When overriding a virtual method, mention virtual again in the declaration (i.e., virtual int foo(); rather than int foo();).

FastDownward: ForDevelopers (last edited 2021-07-02 15:02:48 by PatrickFerber)