Skip to content

Do not confuse simple with unfamiliar

Said by Klaus Iglberger when demonstrating the Visitor Pattern in There Is No Silver Bullet at Meeting C++ 2024.

It is simple, but perhaps you have not used it before.

Things can appear complicated if you are not familiar with them. This can lead to simple solutions being misinterpret as over engineering.

If you are not accustomed to reading and using standard algorithms, perhaps because you have a long history of reading and writing raw for loops instead, you might argue that a raw for loop such as this:

for(int i = 0; i < elements.size(); ++i) {
output[i] = convert(elements[i]);
}

is simpler and easier to read than a modern approach using a standard algorithm:

std::transform(elements.begin(), elements.end(), output.begin(), convert);
std::ranges::transform(elements, output.begin(), convert);

However, don’t let a familiarity bias fool you. In fact, the raw loop has a higher cyclomatic complexity (2 vs. 1). Usage of std::transform expresses intent in a single statement, while the loop forces readers to parse its mechanics, increasing cognitive load.

See also: Simplicity vs Familiarity

When evaluating something new, avoid prejudice simply because it’s unfamiliar.