|
Practical Tools for Simple Design
|
Use #ifndef for include guards instead of #pragma once
Include guard format: <NAMESPACE>_<FILENAME>_<FILE_EXTENSION>
E.g.: Include guard for GameObject.hpp should be GAME_OBJECT_HPP
Internal header should use "" and external headers should use <>
Unless specified, included headers should be the following order:
Different categories are separated with line breaks. If headers are in the same category, headers for the same libraries should be grouped together and be in alphabetical order
E.g. includes for Player.cpp should be
See also: https://clangd.llvm.org/guides/include-cleaner
Member functions and variables declaration should be in the following order, access specifiers should be in the order of public -> protected -> private. Static members should be declared above normal members.
Follow C++ rule of three/five/zero https://en.cppreference.com/w/cpp/language/rule_of_three
C source file: .c C header file: .h C++ source file: .cpp C++ header file: .hpp
Vertex Shader: .vert Fragment Shader: .frag
Source and header files should be PascalCase if it defines a class or struct, otherwise it should be snake_case
Top level folders should only consist of a single word and be lowercase (e.g. src/, include/, lib/)
Source and header file folders should be PascalCase and be the same name as its namespace
E.g.: include/Math/Vector2.hpp should be:
Lower items override higher items if rules collide
| Case | Prefix | Suffix | |
|---|---|---|---|
| Namespace | PascalCase | ||
| Class | PascalCase | ||
| Class member | PascalCase | m_ | |
| Static class member | PascalCase | s_ | |
| Struct | PascalCase | ||
| Struct member | camelCase | ||
| Enum | PascalCase | ||
| Enum element | UPPER_CASE | ||
| Function/Method | camelCase | ||
| Parameter | camelCase | ||
| Variable | camelCase | ||
| Type Alias/Typedef | PascalCase | ||
| Global constant | UPPER_CASE | ||
| Macro | UPPER_CASE | ||
| Template parameter | UPPER_CASE |