This is an old revision of the document!
Coding Style Guide
EEROS is written primarily in C++, and its developers follow the Google C++ Style Guide with some modifications:
#define Guards
We use define guards with a naming similar to Java package names.
For example, lets look at the class Block
using the following source files:
- include/control/Block.hpp
- src/control/Block.cpp
In Java the class Block
would be located in the package org.eeros.control
. Considering this our define guard in the header file looks like this:
#ifndef ORG_EEROS_CONTROL_BLOCK_HPP_ #define ORG_EEROS_CONTROL_BLOCK_HPP_ ... #endif // ORG_EEROS_CONTROL_BLOCK_HPP_
File Names and Extensions
File names:
File names should be the same as the class name. For example, for the class ExampleClass the header file is ExampleClass.hpp and the source file ExampleClass.cpp
If there is more then one class defined in a single file, we use the module name for the file name. A module name always starts with a small letter (e.g. exampleModule.cpp)
File extensions:
C++ Source Code: use .cpp C++ Headerfiles: use .hpp
Variable Names
General guidelines for variable names are as follows:
- Always start with lower case
- No underscores between words in a variable name
- No underscores at the beginning or end of member variables
- No m_ prefix for member variables
- No p_ prefix for private variables
- Constants begin with a lowercase k (e.g. kGain)
- Pointers start with a lowercase p (e.g. pLength) except when:
- It is an Array
- It is a c - String
Examples:
tableName -> OK tablename -> OK, but tableName is better table_name -> Wrong _tableName -> Wrong m_tableName -> Wrong tableName_ -> Wrong
Code Documentation
- The documentation of the code is done with Doxygen.
- The code is documented in the definition, never in the declaration.
- Whenever possible the definition should be separated from the declaration.
- Templates have to be defined directly in the hpp-file. In that case, the documentation will be added there.