First Page
News
Forum
In a Nutshell
About OGDF
FAQs
Key Features
Publications
Documentation
Overview Pages
How-Tos
Developer Resources
Reference Documentation
Get OGDF
Download
System Requirements
Installation (Linux/Mac)
Installation (Windows)
Projects
By OGDF Team
External
Team & Contact
Imprint
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:
Correct code indentation reflecting the structure of control statements is essential to writing readable code. Code is indented by one tab-width (which might be a tab character or four spaces). The following examples show, how indentation is applied for certain statements.
class MyClass { public: int myFunction(int n, double x); int one() const { return 1; } private: 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) { doSomething(); }
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.
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"; doSomethingPositive(); } else { cout << "x is negative or zero"; doSomethingElse(); } switch(switchVariable) { case '\n': doSomething(); break; default: defaultHandling(); }
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.
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') ) { doSomething(); }
