Accidental Code Reuse
May 15, 2021•167 words
Keep it simple stupid! Redundant, duplicate. As software engineers, we're often told that we should reuse what is already available and cut down on the duplicate code we have to write.
This is harder to follow in practice than it sounds. Imagine a scenario where you encounter a piece of code that could be reused to do what you need it to do with a bit of customization. On the surface, this sounds like a good thing. I have worked on several projects in the past where code reuse like this starts but eventually requires so much customization to the original code that everyone acknowledges how ugly the code has gotten and how hard it is to maintain.
If a change in requirements of Feature A were to affect Feature B indirectly due to accidental code reuse that is a huge red flag.
I've been burnt by this too many times that my instinct is now to keep duplicate code until managing the duplicate code gets annoying.