-
Always compile all, test all and lint all.
apollo.sh check
-
Always write unit test and put it along with the source code.
foobar.h foobar.cc foobar_test.cc
-
A bazel target contains at most one header and one source file.
cc_library( name = "foobar", hdrs = ["foobar.h"], srcs = ["foobar.cc"], deps = [ ... ], ) cc_test( name = "foobar_test", srcs = ["foobar_test.cc"], deps = [ ":foobar", ... ] )
-
Simple and unified function signature.
void foobar(const InputType& input1, const int input2, ..., OutputType* output1, ...); // RVO machanism will help you avoid unnecessary object copy. // See https://en.wikipedia.org/wiki/Copy_elision#Return_value_optimization OutputType foobar(const InputType& input);
-
Use const whenever possible.
// Variables that don't change. const int current_size = vec.size(); // Functions that have no side effect. const std::string& name() const;