OpenDUNE:Development/Coding Style
From OpenDUNE
< OpenDUNE:Development(Redirected from Development/Coding Style)
Contents |
General
- C89 code (-ansi -pedenatic for GCC)
- A tab is 4 spaces
- Start lines with tabs, spaces for everything else
- Spaces for aligning things
- Avoid code duplication
- emu_ names are reserved for use with libemu, and should be removed
Comments
- Comments using /*
- Avoid comments after lines
- Avoid useless statements (don't state the obvious)
- Be clear, to the point
- 80 char break
Functions
- CamelCase for function names, no _
- Scope opening of function on newline
- Add Doxygen comments to function, and document what it does (don't forget @param and @return)
/**
* My Test function
*/
void Test()
{
/* .. */
}
Variables
- Start with s_ for local static variables
- Start with g_ for global variables
- thisTypeOfCase for variables names
- A * belongs to the variable, not to the type (so void *t, not void* t)
- Use clear naming (except for 'for' variables, use i, j, k there)
- Don't forget to initialize values where needed/possible
int myNumber = -1; void *myPointer = NULL;
Control Flow
- Scope opening at the end of the line
- Spaces between () and outside (so 'if (1)', not 'if(1)' and not 'if ( 1 )')
- Single statements on the same line, else start a scope
- Use extra () when using bit-operators. The order of execution is not always as clear as you might think
if (1) {
/* .. */
}

