Purpose of this document:
- To provide guidelines for how to write C++ code that is supposed to become part of the TPIE project.
How to modify this document:
- Contact the person who is responsible for the respective rule.
- If the change is approved, substitute your initals for the initials of the previous author.
- If necessary, update the list of maintainers to include your name, initials, and e-mail address.
- Commit the changes (or have some member of the TPIE project commit them).
Maintainers:
- Thomas Molhave (tm, [email protected])
- Jan Vahrenhold (jv, [email protected])
- Henrik Blunck (hb, [email protected])
-
Code has to be documented using Doxygen. (jv)
-
Comments have to be given at least for all public and protected methods and attributes. (jv) Additionally, Doxygen compatible comments for private members as well as for functions, enumeration types and header files are encouraged. (hb)
-
Old C-style comments (
/* */
) shall not be used. (jv) -
Comments for classes, methods and functions shall be written using the "three-slash" style followed and preceeded by a line of slashes. (hb)
Example:
///////////////////////////////////////////////////////// /// /// This class serves as an example. /// /////////////////////////////////////////////////////////
-
Javadoc-style comments may be used for commenting attributes, enumerations and typedefs. (jv)
Example:
/** This is a sample attribute. */ int attribute;
-
An empty expression, e.g., an empty destructor should be commented using
// Do nothing.
(jv)
-
Class names shall be all-lowercase using an underscore to separate parts. (tm)
Example:
class foo_bar_base { ... }
-
Method names shall be all-lowercase using an underscore to separate parts. (tm)
Example:
int foo_bar();
-
Names of attributes, parameters, and variables shall be starting with a lowercase letter and use uppercase letters to seperate parts. (jv)
Example:
int myLocalVariable;
-
Instance and class attributes shall be prefixed by
m_
. (jv)Example:
short m_anAttribute;
-
The use of namespacing shall be enforced. The namespace for the TPIE-project is
tpie::
. (tm) -
Do not import symbols into the global namespace (this prohibits many uses of the
using
keyword). (tm)
- Use
const
modifiers for methods and parameters wherever possible. (tm)
-
The components of a class shall appear in the following order: public - protected - private (jv)
-
Bodies longer than 6 lines of code shall be put in an inline file (.inl) which is included after the class declaration. (tm)
-
The "at-most-one-class-per-file" rule shall be enforced. (jv)
-
Attributes shall not be public. Every attribute shall be accompanied by a
put
- andget
-method. The name of such a method is the name of the attribute prefixed byput_
orget_
(using the naming convention, parts of the attribute name are sepearated by underscores). Read-only attributes shall be accessed by a method that is named just like the attribute. (jv)Example:
int get_my_attribute() const; void put_my_attribute(int myAttribute); int my_readonly_attribute() const;