Version 11 (modified by mgraff, 10 years ago) (diff)

Per meeting discussion

This page documents some coding guidelines.

Python Style

For Python coding, we will use the Python style guidelines:

C++ Style

You can also see the BIND 9 coding guidelines for comparison.

File Name Conventions

Use .cc for C++ source files. This is basically a mere preference and to ensure consistency throughout the package.

Use .h for C++ header files. This is because we may want to provide a C-callable wrapper for some APIs, and some C++ header files are to be included in a C source file. In that case C-compatible file names will look more natural.

Tabs & Indentation

Do not use hard tabs. (Commits may be prevented by a Subversion pre-commit hook.)

Indentation at each level is 4 spaces for C++ and Python, other languages should use what is "usual and expected."

Curly Braces

Always add braces even for a single-line block:

if (something_holds) {
    perform something;

Operator Overloading

When a class supports operator overloading, then there should also be non-overloaded methods, like this:

class Foo {
    bool equals(const Foo &other) const;
    bool operator==(const Foo &other) const { return equals(other); }        

Class Attributes

Accessors for class attributes should be called getXxx().

Mutators for class attributes should be called setXxx().

(where xxx is the attribute)


Please don't start things with underscores (even for private member variables).

Class names are LikeThis, methods are likeThis(), variables are like_this, and constants are LIKE_THIS.

Enumerations are written as

enum EnumName {
  THING_ONE = 1,
} enum_instance;

Where to Put Reference and Pointer Operators

In C++, it seems to be more common to not insert a space between the type and the operator:

int* int_var;
int& int_ref;


Multiline comments can be written in C++ or C style (that is, with or /* */ marks).

 * This is a comment.  It is important probably.
// This is a comment.  It is important probably.
/* This is also ok. */

// As is this.

Comments at the end of lines should usually be C++ style:

class Foo {
    int bar_length;  // The length of the bar in millimeters.


Namespaces will be lower case: isc::dns, or isc::cc.

using namespace should never be used in a header file. They may be used in .cc source files.

Imported Code

If you import code from another project, try to continue the style of the imported project if changes need to be made. This is for two reasons, one is to make merging future versions easier. The other is the encouragement of submitting changes upstream.

Guidelines Adopted by Other Projects