Skip to main content
Comprehensive coding standards for modern C++ (C++17/20/23) derived from the C++ Core Guidelines.

When to Use

  • Writing new C++ code (classes, functions, templates)
  • Reviewing or refactoring existing C++ code
  • Making architectural decisions in C++ projects
  • Enforcing consistent style across a C++ codebase
  • Choosing between language features

Cross-Cutting Principles

  1. RAII everywhere - Bind resource lifetime to object lifetime
  2. Immutability by default - Start with const/constexpr; mutability is the exception
  3. Type safety - Use the type system to prevent errors at compile time
  4. Express intent - Names, types, and concepts should communicate purpose
  5. Minimize complexity - Simple code is correct code
  6. Value semantics over pointer semantics - Prefer returning by value and scoped objects

Functions

Parameter Passing

Pure Functions and constexpr

Classes

Rule of Zero

Rule of Five

Resource Management

Smart Pointer Usage

RAII Pattern

Constants & Immutability

Enumerations

Quick Reference Checklist

Before marking C++ work complete:
  • No raw new/delete — use smart pointers or RAII
  • Objects initialized at declaration
  • Variables are const/constexpr by default
  • Member functions are const where possible
  • enum class instead of plain enum
  • nullptr instead of 0/NULL
  • No narrowing conversions
  • No C-style casts
  • Single-argument constructors are explicit
  • Rule of Zero or Rule of Five applied
  • Base class destructors are public virtual or protected non-virtual
  • Templates are constrained with concepts
  • No using namespace in headers at global scope
  • Headers have include guards and are self-contained
  • Locks use RAII (scoped_lock/lock_guard)
  • Exceptions are custom types, thrown by value, caught by reference
  • '\n' instead of std::endl
  • No magic numbers