This post is a brief of "A Quick Summary of Google C++ Style Guide". If you want a post with better quailty, and more detail, please check the original post.
- The header include order: Related header, C library, C++ library, other libraries' .h, your project's .h.
- Do not use "using namespace xxx" syntax in headers.
- Use .cc instead of .cpp.
- Variables needed for if, while and for statements should normally be declared within those statements, so that such variables are confined to those scopes.
- Constructors should never call virtual functions.
- Use a struct only for passive objects that carry data; everything else is a class.
- Prefer small and focused functions. If a function exceeds about 40 lines, think about whether it can be broken up without harming the structure of the program.
- Within function input parameter lists all references must be const, while output arguments are pointers.
- Never use
std::auto_ptr. Instead, use
File names: all lowercase and can include underscores (_) or dashes (-). For example,
Type names: start with a capital letter and have a capital letter for each new word, with no underscores:
Variable names: all lowercase, with underscores between words. Data members of classes (but not structs) additionally have trailing underscores. For instance,
Constants: named with a leading "k" followed by mixed case. Underscores can be used as separators in the rare cases where capitalization cannot be used for separation. For instance,
const int kDaysInAWeek = 7;
const int kAndroid8_0_0 = 24; // Android 8.0.0
Functions: regular functions have mixed case; accessors and mutators may be named like variables.
Namespace: all lower-case. Top-level namespace names are based on the project name.
Enumerate: mixed type like constants. For instance,
Macros: all upper case letters, include underscores. For instance,
#define PI_ROUNDED 3.0