User Tools

Site Tools


c

C++

Eventually you will have to code in C++. In such case you should have a solid understanding and skill regarding the following topics:

Our Coding Style

In order to manage a larger code base, occasional batch-processing of the sources by command-line tools like sed or awk are necessary. To simplify this and to make the code base more comprehensible to new developers, it is vital to use a unified coding style. Please adhere to the following guidelines, as shown in the following example class implementation, at all times.

template<typename SomeT, int ArgV, typename SomeTagT>
class typical_class  
{
  typedef typename result_of::meta_func<SomeT>::type   InternalType;
 
public:
  typedef SomeT     SomeType;
  typedef SomeType  some_type;
 
  static const int ArgValue  = ValueV;
  static const int arg_value = ValueV;
 
  template <typename AnotherT>
  void member_func(AnotherT const & foo) const
  {
    typedef typename result_of::more_meta<AnotherT>::type  BarType;
 
    if (short_condition)
      do_something();
 
    if ( very_long_condition )
    {
      lot_of_work();
      something_else();
    }
    ...
  }
 
  ...
 
private:
  SomeType  member_;
  int       value_;
};

Mind the following details:

  • No space after template keyword
  • Use of 'typename' for template parameters rather than class
  • Template arguments with trailing 'T' or 'V'
  • Opening braces on next line (one-liners may drop braces)
  • 2 spaces for each level of indentation (no tabs)
  • Public mapped members in both CamelCase and lower_case
  • Mapped types with trailing Type
  • Functions lower_case (including meta functions)
  • Alignment of subsequent code lines:
    SomeType  member_;
    int       value_;

rather than

    SomeType member_;
    int value_;
  • “<TYPE> const &” is preferred over “const <TYPE> &”
  • static const instead of enum for publishing integral template arguments
  • No indentation of public/private in order to easily convert a struct into a class later.
  • Functions may also be formatted as foo( a, b, c ); if this is visually more appealing. Same with < A<B> > for templates.
  • Avoid a trailing _t for the class name when part of the public API
c.txt · Last modified: 2014/05/08 10:39 by viennastar