Please read the following sections carefully before committing new code to the repository.
More...
Please read the following sections carefully before committing new code to the repository.
Conventions
- Never import the
std
namespace. As phrased in c++-faq-lite, one should get over it and type std::
:-). Use std::
even for the symbols which are both in std::
and in the global namespace (e.g., use std::cos()
instead of cos()
).
- Never import any namespace in a header file.
- Avoid importing namespaces directly into the top namespace in implementation files. Imports within the body of a function are ok, but avoiding them is better.
- Use <bracket> include directives, i.e., use instead of
- No dynamic memory allocation (
new Object()
) unless within a smart pointer.
- No
malloc
at all.
- Avoid pointer arithmetic. Iterate STL containers with iterators, unless the index value is needed within the loop.
Style
New code should follow this example:
class RegionOfInterest
{
public:
RegionOfInterest(bool positive = true) :
positive_(positive) {}
virtual ~RegionOfInterest() {}
bool contains(const Vector3 &v) const
{
return (positive_ == contains_(v)) || (next_ && next_->contains(v));
}
protected:
virtual bool contains_(const Vector3 &v) const = 0;
bool positive_;
private:
boost::shared_ptr<RegionOfInterest> next_;
};
}
In particular:
- Two-space indents. No tabs!! Configure your editor to prevent it from inserting tabs.
- Max 80 characters per line.
- Class member variable names end with an underscore:
Writing Good C++
C++ provides the programmer with a lot of freedom, which brings flexibility, but also danger :-)
The c++-faq draws attention to many subtle issues that can arise in C++.