Style Guide

Coding style guide.

Table of Contents


Files

  1. C++ header files have the extension .hpp.
  2. C++ source files have the extension .cpp.

Indentation

  1. 1 tab per indent. You can change the tab settings in your editor so that the code appears indented to your liking.
  2. Try not to use right-aligned 'short' comments. If you must, use spaces to align them, not tabs. The rule is, "tabs to indent, spaces to align".
  3. 1 tab != 8 spaces. This is an assumption that is not always true.
  4. Do not mix tabs and spaces in your indentation!

Naming

  1. Follow the Java naming convention (ClassName, methodName(), variableName).
  2. Prefix data members of classes with the an underscore to avoid conflicts with corresponding query methods. e.g. _variableName, variableName().

Braces

  1. Always use braces for the body of ifs and loops, even when they only contain one statement.
    if (condition)  
    	single_statement;
     
    
    if (condition) {
    	single_statement;
    }
    
  2. Place your braces on the same line as your if, else, for, while and do statement, "Java style".
    if (condition)
    {
    	...
    }
    else
    {
    	...
    }
    
    if (condition) {
    	...
    } else {
    	...
    }
    
  3. Put a space between your if statement and your opening brace.
    if (condition){
    	...
    }
    
    if (condition) {
    	...
    }
    

Using Artistic Style

Artistic Style is an automatic C/C++/Java code formatter. This is the configuration file required to format your code to the above convention:
	
mode=k&r
brackets=attach
indent=tabs=1
brackets=break-closing-headers

Source Control Indentation

If source code style differences become a problem, it may be desirable to implement automatic code reindentation and formatting upon CVS check ins.


Copyright (c) 2002-2003, Greg McIntyre
SourceForge