Follow the Google C++ Style Guide (only for independent projects, the code integrated with other projects follows the corresponding style)
The inclusion of the external library uses quotation marks, for exmaple #include "gtest/gtest.h"
The macro definition should start with the project name PROJECTNAME_
Other scenarios for designing global namespace conflicts are similer. For example, the script directory name can start with projectname-
Forbid C-style cast
Use nullptr instead of NULL
Be serious about precision-sensitive code: use uint8_t, int64_t instead of int, unsigned long, etc.
The principle of using auto is to reduce the amount of code without affecting readability.
Unless interacting with external interfaces (such as pybind), use string_t instead of std::string
Pointer
Except for special situation, do not use new and delete. Use std::make_shared and std::make_unique instead.
shared_ptr should not be abused, if shared ownership is not required, unique_ptr or raw pointer should be used
Quality assurance
New modules should be added with -Werror -Wall -Wextra compilation option.
The return value of external functions (system functions, external libraries) must be checked for error codes or exceptions.
Keep Fail-Fast programming, check as complete as possible (do not affect fritical path performance). Crash the program as early as possible and record detailed information.
In principle, it is forbidden to use global non-constant Variables. (C/C++/Python, etc.)
DCHECK can be used on performance critical paths, and CHECK can be used on non-critical paths.
VLOG(1) for the important traces when debugging
VLOG(2) and above print the required info when you need to debug carefully
Crash case test should be appropriately added to the test.
Performance
Do not create redundant objects (parameter passing, local objects, etc.)
Avoid heavy operations in the loop (such as object creation and release, dynamic memory application and release)