This guide defines the default style for ToolkitProject C++ code. Existing module-local style may be preserved during migration, but new code should follow this document.
- Use modern C++ where it reduces complexity.
- Avoid using advanced language features only for cleverness.
- Prefer explicit ownership and lifecycle over hidden global state.
- Public headers should be conservative and stable.
Preferred structure:
modules/<KitName>/
include/toolkit/<kit>/...
src/toolkit/<kit>/...
src/toolkit/platforms/<backend-or-platform>/...
Backend implementation details belong under src, not public headers.
Use the existing Toolkit naming style consistently inside a module.
General recommendations:
- Types:
PascalCase - Functions/methods: follow existing module style; do not mix styles in one file.
- Private members: follow existing module style; keep naming consistent.
- Constants/macros:
UPPER_SNAKE_CASEonly for preprocessor definitions. - Public APIs should avoid abbreviations unless already established, such as
Gfx,RHI,RPC.
- Include only what is needed.
- Prefer forward declarations in headers when possible.
- Do not include backend headers from public RHI headers.
- Do not include heavy third-party headers in public headers unless unavoidable.
- Keep platform SDK includes inside platform/backend implementation files.
- Document ownership when passing raw pointers across module boundaries.
- Prefer RAII wrappers for native handles.
- Avoid
delete thisunless the type is explicitly designed and documented for intrusive lifetime management. - Avoid storing references to temporary data passed from descriptors.
- Validate descriptor lifetime assumptions in constructors.
- Fail early for invalid descriptors and unsupported backend states.
- Use project assertions for programmer errors.
- Return explicit failure results for runtime/environment errors.
- Do not silently fall back to another backend unless the caller requested fallback.
- Avoid unexpected heap allocation in hot paths.
- Keep allocator behavior explicit in CoreKit-level types.
- Do not allocate large temporary buffers in per-frame paths.
- For GraphicsKit, distinguish host memory, device memory, staging memory, and driver-owned memory when logging.
- Document thread ownership for objects that touch platform APIs or GPU/Audio backends.
- Avoid hidden cross-thread callbacks.
- Avoid blocking waits in worker code unless the scheduling design explicitly allows it.
- Prefer task-system-friendly synchronization primitives over sleep polling.
- Platform-specific code must be isolated behind narrow interfaces.
- Keep
#ifdefblocks out of common logic where possible. - Do not let one platform backend define the public API shape for all platforms.
Use comments to explain non-obvious decisions, not to repeat the code.
Good comment:
// Request one queue per family. The RHI currently uses only queue index 0,
// and requesting all queues increases driver-side initialization overhead.Bad comment:
// Set queue count to 1.