This document describes the coding standards that should be followed when developing within Avida.
Open and close braces should each be on their own line. Do not place the open brace on the same line as the function signature. The only exception to this rule is single line class methods, in which both braces are allowed to be on the same line as the code (but only in pairs). Examples:
void cFoo::Method() { // code goes here } // ... in a class inline void Method() { ; } inline void Method() { // longer code in here }
void cFoo::Method() { // code goes here } // ... in a class inline void Method() { ; }
The open brace should go on the same line as the control structure, the close brace on its own line. Examples:
while (foo) { // code goes here }
while (foo) { }
The same formatting rules as for/while/etc., but if there is an else clause the close brace should go on the same line as the else statement. Single line if else statements should not get braces, unless they accompany a multi-line statement. Examples:
if (foo) { DoSomething(); DoAnotherSomething(); } else { DoADifferentSomthing(); } if (!foo) CallAFunction(); else CallBFunction();
if (foo) { DoSomething(); DoAnotherSomething(); } else DoADifferentSomthing(); if (!foo) { CallAFunction(); } else CallBFunction();
Do not use any space between the name and the open parenthesis, inside the parentheses, or before commas that separate arguments. A single space should follow commas that separate arguments. Examples:
void cFoo::Method(int arg1, double arg2); int aFunction();
void cFoo::Method( int arg1 , double arg2 ); void cFoo::Method (int arg1, double arg2); int Function ( );
Control structures such as if, for, while, do, and switch statements use a single space before the open parenthesis, but spaces inside them.
#ifndef cPopulation_h #define cPopulation_h // Code goes here #endif
#ifndef cPopulation_h #include cPopulation_h #endif
i position this_is_my_var
m_type m_lexeme m_my_component
Sort() ThisIsMyFunction() Inst_Divide()
cGenome tArray eHeadTypes sSomeData
NUM_REGISTERS MAX_STRING_LENGTH
cGenome.h tArray.h cPopulation.cc