ALICE O² C++ Comments Guidelines

Vasco Barroso
Alina GrigoraȘ
Ivana Hřivnáčová
Matthias Kretz
Adriana Telesca
Barthélémy von Haller

This document is based on the work of
B. Weinberger, C. Silverstein,
G. Eitzmann, M. Mentovai
and T.Landray
at http://google-styleguide.googlecode.com,
C++ Google Style guide, Revision 3.274
under the CC-By 3.0 License

Each style point has a summary for which additional information is available by toggling the accompanying arrow button that looks this way: . You may toggle all summaries with the big arrow button:

Toggle all summaries
Table of Contents

Important Note

Displaying Hidden Details in this Guide

link
This style guide contains many details that are initially hidden from view. They are marked by the triangle icon, which you see here on your left. Click it now. You should see "Hooray" appear below.

General

General Guidelines

link

Though a pain to write, comments are absolutely vital to keeping our code readable. The following rules describe what you should comment and where. But remember: while comments are very important, the best code is self-documenting. Giving sensible names to types and variables is much better than using obscure names that you must then explain through comments.

When writing your comments, write for your audience: the next contributor who will need to understand your code. Be generous — the next one may be you!

Doxygen

link
Following an evaluation of different code documentation tools, Doxygen has been selected. Doxygen [1] allows different comments style. We recommend to use a block of C++ comment lines, where each line starts with an additional slash.
/// ... text ...
/// ... text ...

Mandatory Documentation

link
There are a certain number of items that must be documented. They are:
  • Files.
  • Classes.
  • Functions.
  • Data members.
  • Namespaces.
  • Enumerations and enumerators.
  • Macros.
The following sections show how to document each one of these items. First of all, we will go through general guidelines that will help you to document your code.

Comments Style

link
Use the /// syntax for the comments going in the Web documentation, the // syntax for explicative comments in the code and the /* */ syntax only for the comments within one line.

Punctuation, Spelling and Grammar

link
Pay attention to punctuation, spelling, and grammar; it is easier to read well-written comments than badly written ones.

Special Characters

link
While non-ASCII characters are not allowed in names used in the code, use of Unicode e.g. for proper math formulas in comments is encouraged.

How to Document Your Code

Files

link
Start each file with copyright boilerplate, followed by a description of its contents.

Classes

link
Every class definition should have an accompanying comment that describes what it is for and how it should be used. The comment should be placed just before class keyword.

Functions

link
Declaration comments describe use of the function; comments at the definition of a function describe operation.

Class Data Members

link
Each class data member (also called an instance variable or member variable) should have a comment describing what it is used for. If the variable can take sentinel values with special meanings, such as a null pointer or -1, document this.

Namespaces

link
Every namespace definition should have an accompanying comment that describes what it is for. The comment should be placed just before namespace keyword.

Enumerations

link
Always provide a description of the enumerations and their enumerators values.

Macros

link
Always provide an explanation of what the macro is used for and how.

Other

link
Complex code blocks/lines, To do comments, etc.

References

[1] Doxygen [http://www.doxygen.org]