Coding style

This is a draft of coding style rules we follow at IMP!

  1. Avoid code duplication.
  2. Avoid code duplication like the plague:
    • creates hard to spot bugs
    • makes things harder to think about, and code longer to read
    • makes thread safety harder to ensure
    • performance is harder to optimize
    In c++:
    • no code copy and paste. Use functions. You can achieve generalization with parameters or templates
    • no forward declarations. Declare things in order
    • getters and setters should return auto types
  3. Keep functions short. Few lines. If a function grows more than 40 lines, think about splitting it in some smaller functions.
  4. Variable names should be as long in proportion as the object lifetime. Ex:
    for(int i = 0; i < 10; ++i) {std::cout << i << '\n';}
     
    void compute_median(vector<int> vec) {
        // n_th element ...
        // ... done
    }
     
    void run_many_test() {
        std::vector<Test> tests_collection;
        // T1...
        // ...
        // T2...
        // T3...
        // T4...
        // ...
        // ...
        // ...
        // ...
    }
     
    static MissileLauncher global_unique_missile_launcher;