Today I would like to announce a new coding style I will be implementing for all of my projects. This style is heavily inspired by DOOM 3 source code style with some of my own tweaks. The style is broken down as follows:
Comments:
the commenting style allows for programs like Doxygen to work more effectively
/**
* This is the new commenting style for functions
*/
void Example( int parameter );
int example = 0; /**< This is the new commenting style for variables */
Brackets
For brackets I do NOT like to use trailing braces and I use 4 spaces for indentation
bool isValid = false;
if( isValid )
{
return true;
}
//else, else if, etc. statements should be on the same line as the if statement
else
{
return false;
}
Padding
Pad parenthesized expressions with a single space
//function declarations
void Example( int parameter, int parameter2);
//function calling. (trail commas with a single space)
Example( 5, 10 );
//arithmetic
x = ( 1 + 5 );
Variable and Function names
//names start with a lowercase letter
int example = 0;
//names with more than one word follow the preceding rule and use camel notation
bool secondExample = false;
//function names start with an Upper case letter
bool Example();
//function names start with an Upper case letter and use camel notation
bool SecondExample():
Classes and member layout
//class names with multiple words begin with a lower case letter and use Camel notation
class exampleClass
{
//the order of protection levels are: public, protected, then private
public:
//class and struct member variables have the same naming conventions as variables
//indent the names of class variables and class methods to make neat columns
float x; /**< indent variable comments as well to maintain a column */
float y; /**< */
float z; /**< */
//also use constant member functions where applicable
float Example( void ) const;
//class and struct member functions have the same naming conventions as functions
bool ExampleFunction( void ) const;
};
/*
the ordering of class members and functions should be:
- list of friend classes
- public variables
- public methods
- protected variables
- protected methods
- private variables
- private methods
*/
Typedefs and structs
//typedef and struct names always end with _t
typedef void( *exampleFunctionPointer_t )( void );
struct exampleStruct_t
{
};
Macros
//macro names use all upper case letters. multiple words are separated with an underscore
#define EXAMPLE_MACRO 0
refer to the DOOM 3 coding standards for more information.