4 ms·
> Trying to deduplicate code that is structurally similar but has different aims just creates a problem later on. This is one of the most important lessons I'v
by dwaltrip 7y ago
> Trying to deduplicate code that is structurally similar but has different aims just creates a problem later on.
This is one of the most important lessons I've learned in software. Abstractions work well when the snippets in question have similar, coupled requirements. The proposed abstraction must target the shared requirements, or it will soon cause more problems than it solves as the snippets diverge due to their different purposes. Structural similarity alone provides very limited opportunity for a robust abstraction.
A rough heuristic that may indicate one of these problematic abstractions is the number of special cases and if-elses that are continually being added to make it work.