4 ms·
I think there is a good way to figure out when to apply abstraction. The question to ask is whether the abstraction reduces the cognitive load on the reader.
by Periodic 16y ago
I think there is a good way to figure out when to apply abstraction. The question to ask is whether the abstraction reduces the cognitive load on the reader. Abstractions that reduce the cognitive load by eliminating redundant code, highlighting commonalities, and reducing LoC are generally an improvement. Abstractions that create unnecessary complexity, obfuscate, or result in more LoC are generally a decline in quality.
It may not be true in all situations, but I think this benchmark is a good one, as it accounts for the environment of the developer. If the code is only used once, it isn't worth it to abstract it. Once you have two implementations and need to add a third, you may realize they have commonalities and so abstracting and refactoring make sense.