Skip to content

Use shorthand variables to Improve Readability

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()) {
// ...
}

Is easier to digest than:

if (GameWorld::Objects::getActiveObjects().size() > 10) {
// ...
}
if (GameWorld::Objects::getActiveObjects().empty()) {
// ...
}

This not only makes your code easier to read and maintain, but also prevents redundant calls to the accessor function.