Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Separate inline headers: We allow putting inline functions in separate files, using the suffix -suffix .inline.h or -impl.h or .inline.h. This can speed up compile times by reducing the volume of code to be compiled and reducing dependencies between headers.

Scoping

  1. namespaces the using namespace directive is encouraged allowed in .cc files in limited cases where it greatly reduces code volume.
    1. Pros: reduces code volume, less churn in "using namespace::class" directives.
    2. Cons: pollutes the namespace, causes conflicts, makes it more difficult to determine the type of an object

Functions

  1. default function arguments we use default function arguments
    1. Pros: clean syntax, reduced code volumne
    2. Cons: function pointers are confusing in the presence of default arguments

...

Commenting

Formatting

The .clang-format file checked into the Impala repository should be used to format whitespace (see Contributing to Impala for more info). The .clang-format file is the source of truth for whitespace formatting, except when its output significantly diverges from practices in the existing codebase or from common sense. In those cases .clang-format should be updated.

Some key differences from the Google C++ style are:

  1. Line Length We use 90 character line lengths
  2. TODO Comments we do not include the name in the TODO comment
  3. Function Declaration we line wrap differently than google, for example doGoogle, typically packing more parameters per line, e.g.:
Code Block
// Google Recommends:
ReturnType LongClassName::ReallyReallyReallyLongFunctionName(
    Type par_name1,  // 4 space indent
    Type par_name2,
    Type par_name3) {
  DoSomething();  // 2 space indent
  ...
}
// we use:
ReturnType LongClassName::ReallyReallyReallyLongFunctionName(
    Type par_name1, Type par_name2, Type par_name3) { // 4 space indent
  DoSomething();  // 2 space indent
  ...
}
Code Block
// Google Recommends:
ReturnType ClassName::ReallyLongFunctionName(Type par_name1, Type par_name2,
                                             Type par_name3) {
  DoSomething();
  ...
}
// We use
ReturnType ClassName::ReallyLongFunctionName(Type par_name1, Type par_name2,
    Type par_name3) {  // 4 indents
  DoSomething();
  ...
}

 

    3. Conditionals we format conditionals as follows

Code Block
// Google Recommends:
if (x == kFoo) return new Foo();
if (condition)
  DoSomething();  // 2 space indent.
if (condition) {
  DoSomething();  // 2 space indent.
}
// we only use:
if (x == kFoo) return new Foo();  // If the whole line fits into the 90 character limit
if (condition) {
  DoSomething();  // Otherwise, 2 space indent.
}

Third-Party Libraries

  • Boost - we use a different set of Boost libraries. Reducing # of dependencies is encouraged and adding dependencies to new libraries should be carefully evaluated.