Skip to content

Latest commit

 

History

History
52 lines (45 loc) · 1.11 KB

best_coding_practice.md

File metadata and controls

52 lines (45 loc) · 1.11 KB

Best Coding Practice

  1. Always compile all, test all and lint all.

    apollo.sh check
  2. Always write unit test and put it along with the source code.

    foobar.h
    foobar.cc
    foobar_test.cc
    
  3. 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",
        ...
      ]
    )
    
  4. 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);
  5. 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;