Summary of General C++ Coding Standards at the NFRA
- RULE 1.1:
- Each file must start with a copyright notice.
- RULE 1.2:
- Each file must contain an RCS identifier.
- RULE 1.3:
- The common header file NFRA.h should always be included first.
- RULE 1.3:
- Use angle brackets to include a header file.
- RULE 2.1:
- File types have to be .h, .cc and .icc.
- REC 2.2:
- Declare and implement only one class in a file.
- REC 2.3:
- File names have to be unique in as large a scope as possible.
- RULE 3.1:
- A header file has to be guarded against multiple inclusion.
- RULE 3.2:
- Forward declare classes as much as possible.
- RULE 3.3:
- Place inclusions after the forward declarations.
- RULE 4.1:
- Use // for comments.
- RULE 4.2:
- All comments have to be written in English.
- RULE 4.3:
- A header file has to contain comments describing class and functions.
- RULE 4.4:
- Document the functions needed for a template argument.
- RULE 4.5:
- Use #ifdef iso. /*...*/ to uncomment code.
- RULE 5.1:
- Use descriptive names and use capitals as needed.
- REC 5.2:
- Use the prefix "its" for names of class member variables.
- REC 5.3:
- Use the prefix "their" for names of static class member variables.
- REC 5.4:
- Use the prefix "the" for names of global variables.
- REC 5.5:
- Use a meaningful prefix (a verb) for names of boolean functions.
- RULE 6.1:
- Give names to arguments in function declarations.
- RULE 6.2:
- Each function argument should be specified on a separate line.
- REC 6.3:
- Do not use variable argument lists (...).
- REC 6.4:
- Pass objects by reference; pass builtin data types by value.
- RULE 6.5:
- Declare arguments passed by reference or pointer const when
not changing them.
- RULE 7.1:
- Put inline functions in file "Class.icc".
- REC 7.2:
- Inline functions only when needed for performance.
- RULE 7.3:
- The keyword "inline" should be used in both declaration and
implementation.
- REC 8.1:
- Declare local variables at the point where they are needed.
- REC 8.2:
- Take care of variables declared in a for-statement.
- REC 8.3:
- Use braces in a case label in a switch statement.
- RULE 9.1:
- Use only one declaration or statement per line.
- RULE 9.2:
- The * or & should immediately follow the type.
- RULE 9.3:
- Use braces and indentation in the proper way.
- RULE 9.4:
- Always use braces in if, for and while statements.
- REC 9.5:
- Initialize member variables with a constructor initializer list.
- RULE 10.1:
- Use the keyword explicit to denote that a constructor should
not automatically convert.
- REC 10.2:
- Define conversion operators only when really needed.
- RULE 11.1:
- Never use malloc and free.
- REC 11.2:
- Set a pointer to 0 after deleting an object.
- RULE 11.3:
- Use [] when deleting an array of objects.
- REC 11.4:
- A class allocating an object should also destruct it.
- REC 12.1:
- Do not use pointer-to-member.
- REC 12.2:
- Do not use multiple inheritance.
- REC 12.3:
- Do not use the keyword "register".
- REC 13.1:
- Global variables should not be used if possible; use static class
member variables.
- REC 13.2:
- Declare enums and typedefs in a class.
- RULE 14.1:
- Declare functions and data in order public-protected-private.
- RULE 14.2:
- Declare data variables only as private and at the end of the class.
- REC 14.3:
- A class should contain default constructor, copy constructor,
destructor, and assignment operator.
- RULE 14.4:
- A destructor has to be declared virtual in a base class.
- RULE 14.5:
- Declare member functions const when no changes are made.
- REC 15.1:
- Do not use = when constructing an object.
- RULE 15.2:
- Always test for self-assignment in the assignment operator.
- RULE 15.3:
- Use 0 (not NULL) when assigning or testing pointers.
- RULE 15.4:
- Use unsigned when a variable cannot have negative values.
- RULE 15.5:
- Use a typedef to define a pointer-to-function.
- REC 15.6:
- Use symbolic names for constants.
- REC 15.7:
- Use enum or static const members iso. #define.
- REC 15.8:
- Use pre- and postconditions in a function.
- REC 15.9:
- Use a temporary variable instead of a function call in loop guards.