Duplication is a crime against code. DRY is part of the developer gospel. Even worse a sin however is premature optimization. This tweet really hits home with it:
I don't avoid duplication. I wait for it to occur, let it inforn me, and then clean it. I choose Emergence over Speculation. https://t.co/pJ5uDBElH5
— Michael (Doc) Norton (@DocOnDev) July 12, 2017
Michael couldn’t be more right. Instead of trying to project whether you may reuse a block of code or not just wait. Eventually patterns will emerge that show you that you are in fact duplicating code. When this happens it’s time to optimize and you’ll be able to utilize the patterns that emerged to better inform your function or method that you use to reduce this block of code’s footprint.
Happy coding out there!