Code Duplication vs Abstraction: Expert Insights
Executive TL;DR:
- Code duplication can be cheaper than wrong abstraction in some cases.
- Finding the right balance between code duplication and abstraction is key.
- Single source of truth principle should always be followed.
The Internet’s Verdict: 60% Hyped, 40% Skeptical
Introduction to Code Duplication and Abstraction
Code duplication and abstraction are two concepts that have been debated by developers for a long time.
Forum Voices
Many experts have shared their opinions on this topic. For example:
No it’s not. This has always been a needlessly iconoclastic rather than sensible suggestion. At the very least it is not once you’re working at the wrong kind of scale.
Another expert notes:
Too many abstractions are bad. Too many code duplication is bad. Part of being a good engineer is finding the right balance.
Conclusion
In conclusion, while code duplication can be cheaper than wrong abstraction in some cases, finding the right balance between code duplication and abstraction is key to writing efficient and maintainable code.
I believe that single source of truth is a principle that should always be followed. If there’s duplicated code where it’d be a bug if they diverge, then you should refactor.
Focus Keyword: Code Duplication