-
Notifications
You must be signed in to change notification settings - Fork 72
Coding Practices
Michael Iatauro edited this page Oct 21, 2014
·
2 revisions
- Ensure you declare variables and methods in their narrowest scope.
- If you declare a static variable inside a non-static method, double check that the method should not be static and also double check that the variable should not be a member of the class.
- We discourage writing code in header files unless needed for templates or proven performance.
- Use STL classes and methods unless what you need is not provided. Same goes for any other code. Reuse as much as possible.
- Include system headers by using the angle bracket style. (
#include <stdio>
) - Include user files by using the double quote style. (
#include "File.h"
) - Do not define your own pre-processor macros to control level of or presence of debugging output or error checks.
- Use the
std::
prefix, or 'using namespace std;' when using STL. - Put Europa code in the Europa namespace.
- Use DEFINE_GLOBAL_CONSTANT and DECLARE_GLOBAL_CONSTANT for globals.
- When handling static data, you must provide an automatic purge mechanism or provide an explicit purge method.
- We should standardize method calls to initialization and termination methods. Such as nddl initialization which cascades onto constraint engine initialization.
- Use const iterators unless you have to use a non-const iterator.
- When using const iterators, use
++iterator
rather thaniterator++
.
- Direct pointer references are discouraged; use class Id instead.
- When creating a reference, create an m member that holds the id that gets constructed in the constructor initializer, in the destructor the m should be removed.
- When deleting references to ids call delete on the cast operator (e.g.
delete (ConstrainedVariable *) ref
).
- Define an enumerated type to handle number references instead of using magic numbers.
- Capitalize names of classes. When composing names for classes capitalize the first letter of each word.
- Declare a virtual destructor.
- Declare a protected constructor.
- Declare all functions pure virtual.
- Declare a method const where possible.
- Do not return bare pointers or non-const references.
- If the caller can own a data structure that is to be populated in the callee, create the data structure in the caller and then pass it by reference as an argument.
- Avoid copying of data structures where possible.
- Declare non-primitive arguments as const references.
- Return non-primitive values as const references.
- Use checkError to express pre-conditions.
- Use checkError to express invariants.
- Use checkError to express post-conditions.
- Avoid using non-const functions in checkError tests.
- Do not use assert.
- Do not use Id::isValid outside of checkError.
- Do not write
if (Test) checkError(...Check...);
. WritecheckError(Test && ...Check...)
.
- Use the Europa debugging output management system.
- Do not put debugging output into stdout or stderr.
- Use doxygen style comments with the javadoc style keywords.