Make intentional design decisions
Every line of code embodies at least one design choice. Write code with deliberate intent rather than by accident or habit. Avoid just-in-case programming When you don’t know, follow default guidelines.
Every line contains design decisions
Section titled “Every line contains design decisions”Even seemingly simple code involves multiple choices:
auto result = process(data);This single line contains decisions about:
autovs explicit type (explicitness vs brevity)- Value vs reference return (ownership and performance)
- Return parameter vs out/in-out parameter
- Function naming (expressing intent and understanding)
- Error handling strategy (exceptions, error codes, or optional)
Common design decisions
Section titled “Common design decisions”Every day coding involves choices like:
- Memory management: Stack vs heap allocation
- Semantics: Value vs Reference Semantics
- Const correctness:
constvs mutable - Containers:
std::vectorvsstd::arrayvsstd::deque - Algorithms: Raw loop vs algorithm vs range-based for
- Error handling: Exception vs error codes vs std::optional
- Abstraction: Template vs inheritance, extract class/function vs inline code
- Extension: Support extension of operations or extension of types (Expression Problem)
Following defaults
Section titled “Following defaults”It requires years of experience to be able to always know what decision to make. Fortunately, in many situations we can default to generic guidelines such as the C++ Core Guidelines. It is generally better to follow standard conventions, than to do something unusual by accident.
Express intent clearly
Section titled “Express intent clearly”Make your design decisions visible to other developers:
- Clear naming reveals intent
- Code structure should reflect the problem domain
- Comments explain why, not what
- See also: Write code that reads like the problem that it solves
Reinforce intent
Section titled “Reinforce intent”- Use tests as executable documentation - Tests express intended behavior
- Apply decisions consistently across the codebase
- Justify and document any deviation from the standard
- Code reviews help ensure intent is clear
Understand trade-offs
Section titled “Understand trade-offs”Every design decision involves trade-offs. Being intentional means:
- Understanding what you’re gaining and losing
- Recognizing that context matters - the “best” choice depends on constraints, team, and domain
- Deviating only from conventional practices (C++ Core Guidelines, idiomatic C++, team conventions, industry best practices) when you have justifiable reasons