Coding Style Guidlines - Sheng-Cheng/OpenMACE GitHub Wiki
This document introduces the coding standards for the ISAAC project.
Any .cc/.cpp file is to have an associated .h file with the same name. A .h/.cpp file is to have only one class inside of it named the same. Be weary of the file length when designing classes. If the class is very large containing many long methods, it's likely that the objects other objects should be made. Be weary of the length of each method, if a method becomes very long consider creating new subroutines. If a object contains repeating code, consider creating a new subroutine to perform the duplicate code.
Avoid any member with a access modify greater than private.
Make any members private, then use accessors and mutators to get and set the member.
The exception to this is if the member is a public const
.
Files
Files are to be named in lower case with '_' separating words.
Class/Types
Classes and any types are named by CamelCaps, first letter of each word is to be capitalized.
Functions/Methods
In general, methods inside an object are to be named by CamelCaps, first letter of each word is to be capitalized. The exception is for accessors and mutators (get and set) where "get" and "set" are placed in front of the variable name being accessed and mutated in CamelCaps.
For example the following are appropriate method prototypes
void setCount(int);
void AddToCount(int numberToAdd);
int getCount();
Variables
Use camelCaps to name variables, first letter of each word is capitalized except for the very first letter.
Avoid using names with no meaning such as int A
.
In general, avoid using i
, j
, k
as looping indexers.
Using such names makes it easy to accidentally overwrite inside a previously defined indexer.
The exception to this rule is if the loop takes up less than half the screen such that the variable being used can clearly be seen.
All member variables in an object should be prefixed by 'm_'.
A class should be outlined as follows:
- public/protected/private (in order) static const variables
- public/protected/private (in order) static functions
- protected/private members
- public/protected/private methods
Code in the ISAAC project is documented using Doxygen. Refer to the Doxygen Documentation for a detailed discussion on the syntax of Doxygen.
It is prefered that methods be documented using //!
comment block, which can be auto-generated by Qt.
//!
//! \brief AddModule Add module to data fusion
//! \param module Module to add
//!
void AddLocalModule(const std::shared_ptr<ModuleBase> &module);
In addition each file is to have a header
/**
\* @file
\* @author
\*
\* @section PROJECT
\*
\* This is a part of the Heron System's project ISAAC.
\*
\* @section DESCRIPTION
\*
\*/