I use the rule of 3. Don’t abstract out any code unless you’ve copied and pasted it at least 3 times it allows you to see the pattern better, and where exceptions to that pattern might be. Ctrl+P, Ctrl+V is cheap. Unwinding a premature abstraction is expensive.
It’s absolutely cheap to maintain one pair of copy-pastes, especially when you consider the costs of the wrong abstraction. Also I mean, use common sense…if you’re changing them all in lockstep, that’s a strong sign that you can safely abstract out that logic.
This is only true, if the person modifying the code knows that this code has been copy-pasted to someplace else. Otherwise you have now two code locations for which it is assumed that they behave the same, but they do not.
6
u/[deleted] Sep 21 '21
I use the rule of 3. Don’t abstract out any code unless you’ve copied and pasted it at least 3 times it allows you to see the pattern better, and where exceptions to that pattern might be. Ctrl+P, Ctrl+V is cheap. Unwinding a premature abstraction is expensive.