Boomerang Coding Conventions

C++ source code should be indented with tabs, not spaces; use 4 character tabs. In vim, you put the following in your .vimrc

:set tabstop=4
:set shiftwidth=4
:set noexpandtab
:set nocindent

Braces should be used consistently as follows:

void myfunc(params) {
    if (pred) {
    } else {
        while (pred) do {
Keywords such as if should be followed by one space; there should be no space immediately after an open parenthesis, or immediately before a close parenthesis.

Lines should be limited to 120 characters; break longer lines. If an if statement has to be broken, use an extra tab to indent the continuation, e.g.
    if (very very very very very very very very very very very very
            very very long predicate) {
        statement; ...

There are parts of the code that were still formatted for 80 columns maximum; these are gradually being reformatted to 120 characters.

In header files, reserve 2 tabs for the optional keywords virtual or static, and reserve three tabs for the return type. Constructors and destructors which have no return type should therefore be indented 5 tabs. A few headers still need to be reformatted to this standard.


Everyone likes comments in the source code he reads. That's why we add them. Use C++ style comments, and put a comment on the line before the instruction it applies to when telling about the overall things that are happening, and put remarks about the line itself after the line. Example:

// We are now going to shoot ourselves in the foot
// First grab a gun
bulletCount++; // Just to be on the safe side
// Then the shooting part:
shoot(foot); // Note: don't try this at home

Oh, and please don't do this:

counter++; // Increment the counter by one


Doxygen can generate HTML documentation from source files. It even gets more usefull when special comments are added to the code. Example:

* The program will be subsequently be loaded, decoded, decompiled and written to a source file.
* After decompilation the elapsed time is printed to std::cerr.
* \param fname The name of the file to load.
* \param pname The name that will be given to the Proc.
* \return Zero on success, nonzero on faillure.
int Boomerang::decompile(const char *fname, const char *pname);

Functions should be documented in the header files. For short comments, instead of /** ... */ this can be used:

/// The program will be subsequently be loaded, decoded, decompiled and written to a source file.
int Boomerang::decompile(const char *fname, const char *pname);

For information about the special commands see Special Commands

Last modified: 22/Sept/06: Removed that braces are optional when there is only one statement, changed <verbatim> to <pre>