Chapter 2. Code Style
Prev |  | Next

# Chapter 2. Code Style

- indent with tabs (width 8)

- don't write CPP when you can write C++: use inline functions and constexpr instead of macros

- comment your code, document your APIs

- the code should be C++14 compliant, and must compile with GCC 4.9 and clang 3.4

- report error conditions with C++ exceptions, preferable derived from `std::runtime_error`

- all code must be exception-safe

- classes and functions names use CamelCase; variables are lower-case with words separated by underscore

- Some example code:

      static inline int
      Foo(const char *abc, int xyz)
      {
              if (abc == nullptr) {
                      LogWarning("Foo happened!");
                      return -1;
              }

              return xyz;
      }

Prev |  | Next
Chapter 1. Introduction | Home | Chapter 3. Hacking The Source