Code Formatting
Starting with the post-release 3.0 codebase, we are trying to unify the coding style of our source code. All new patches and contributions should strive to follow the same style (See here for god reasons why this is important)
Indentation: Required to be using 4 characters per level, no tabs allowed. Set your editor to insert spaces for tabs.
Comments: Self explanatory code with descriptive naming of methods and variables is preferred over comments. Only use comments if you feel the intent of your code or the algorithm used is not obvious from a casual reading of the code.
A general sample of the preferred style follows below. Follow this template for whitespace around braces, parentheses, operators and control statements.
For Eclipse users there is a Code Formatter template available at http://opencpn.org/ocpn/downloads/doc/codestyle.xml
For Uncrustify users there is an uncrustify.cfg available at http://opencpn.org/ocpn/sites/default/files/users/registry/beautify.png (Use Save As... for this file, it is a text file disguised as an image. Should be named "beautify.cfg")
Indentation: Required to be using 4 characters per level, no tabs allowed. Set your editor to insert spaces for tabs.
Comments: Self explanatory code with descriptive naming of methods and variables is preferred over comments. Only use comments if you feel the intent of your code or the algorithm used is not obvious from a casual reading of the code.
A general sample of the preferred style follows below. Follow this template for whitespace around braces, parentheses, operators and control statements.
For Eclipse users there is a Code Formatter template available at http://opencpn.org/ocpn/downloads/doc/codestyle.xml
For Uncrustify users there is an uncrustify.cfg available at http://opencpn.org/ocpn/sites/default/files/users/registry/beautify.png (Use Save As... for this file, it is a text file disguised as an image. Should be named "beautify.cfg")
#include <math.h>
class Point {
public:
Point( double x, double y ) :
x( x ), y( y )
{
}
double distance( const Point& other ) const;
int compareX( const Point& other ) const;
double x;
double y;
};
double Point::distance( const Point& other ) const
{
double dx = x - other.x;
double dy = y - other.y;
return sqrt( dx * dx + dy * dy );
}
int Point::compareX( const Point& other ) const
{
if( x < other.x ) {
return -1;
} else
if( x > other.x ) {
return 1;
} else {
return 0;
}
}
namespace FOO {
int foo( int bar ) const
{
switch( bar ){
case 0:
++bar;
break;
case 1:
--bar;
default: {
bar += bar;
break;
}
}
}
} // end namespace FOO