Open Graph Drawing Framework
current version:
v.2012.07 (Sakura)


Back to Coding Standards

Source-code must be editable in a usual text editor. Since developers use different development environments and systems, the text needs to be portable and shall not assume any properties of specific environments. The following general rules hold:

  • The tab width is set to 4 characters. Usually, code is indented using the tab-character; it is crucial that the text editor you are using has tab width set to 4 spaces, otherwise the displayed code will be a mess!

Code indentation

Correct code indentation reflecting the structure of control statements is essential to writing readable code. Code is indented by one tab-width (a tab character). The following examples show, how indentation is applied for certain statements.

Class declarations

class MyClass
    int myFunction(int n, double x);
    int one() const {
        return 1;
    double m_somePrivateData;

The opening curly brace is placed in a new line, visibility specifiers are not indented, member declarations are indented by one tab.


int MyClass::myFunction(int n, double x)

We place the opening curly brace in a new line, or in the same line with a space in front of it; the latter is shown in the class declaration example above.

Compound statements

These examples show how indentation is used with loops and conditional statements.

    for (int i = 0; i < n; ++i) {
        cout << i << " ";
    if (x > 0.0) {
        cout << "x is positive";
    } else {
        cout << "x is negative or zero";
    switch (switchVariable) {
    case '\n':

Curly braces may be omitted where allowed by C++. Empty lines should be used if this improves readability. It is also allowed to place the first opening curly brace in a new line, if the line is quite long and this improves readability.

Line breaks

If not all arguments of a function declaration fit into a single line, each argument is placed into a single line and all arguments are left-aligned indented by one tab:

void parallelFreeSortUndirected(
    const Graph &G,
    SListPure<edge> &edges,
    EdgeArray<int> &minIndex,
    EdgeArray<int> &maxIndex)
    // implementation

If expressions (e.g., in if- or while-statements) are too long, they should be separated according to the structure of the expression. A following opening curly brace has to be put into a new line, e.g.,

    if (('0' <= inputChar && inputChar <= '9')
     || ('a' <= inputChar && inputChar <= 'z')
     || ('A' <= inputChar && inputChar <= 'Z')) {
tech/cs_formatting.txt · Last modified: 2014/03/09 21:07 by stephan
This page is driven by DokuWiki