Skip to content

Write code that reads like the problem that it solves

Code that clearly expresses its intent reduces cognitive load and makes maintenance safer. These techniques help transform implementation details into domain-focused expressions that communicate purpose rather than mechanics.

See Do not confuse abstraction with obfuscation

if (isActive(user) && hasPermissionToExecute(user)) {
process(request);
}

Long namespace-qualified names or verbose types can drown out the logic. Hide them behind clean aliases so the algorithm is what stands out.

using PlayerName = game::player::types::PlayerName;
using ScoreValue = game::score::types::ScoreValue;
using PlayerScoresByName = std::unordered_map<PlayerName, ScoreValue>;
PlayerScoresByName playerScores;

When you repeatedly access a deeply-nested or verbose object, consider introducing a shorthand variable for clarity and efficiency.

const auto& activeObjects = GameWorld::Objects::getActiveObjects();
if (activeObjects.size() > 10) {
// ...
}
if (activeObjects.empty()) {
// ...
}

Overly explicit typing can distract from what is happening. With auto, the focus shifts to the logic itself.

// Without auto: explicit type for iterator in std::find
std::vector<int>::const_iterator it = std::find(vec.begin(), vec.end(), 42);
// With auto: type inference removes distraction
auto it = std::find(vec.begin(), vec.end(), 42);
  • Use ranges instead of index-heavy logic.
  • Use adapters to prevent accessing external API’s directly