DEV Community

loading...

Discussion on: The Demise of Reuse

Collapse
jaroslavholan profile image
Jaroslav Holaň

I agree. I spend a lot of time modifying abstractions that turned out to be inflexible designs that are difficult to change when new requirements show their ugly heads.

The only thing that I dislike more than duplicate code is so-called reusable code that is littered with one-offs.

"I'll just put the new behavior in the base class and guard it with a boolean parameter that defaults to false so that the subclass can override the parameters to get the new behavior." - every code monkey at some point in their lives

I see this kind of attitude a lot in projects where code quality is neglected when the deadline approaches. It somewhat disgusts me when programmers do this. What's worse is that the management in a lot of places encourages it because it allows you to deliver sooner at the cost of code quality and maintainability.

Often I end up rebuilding bad abstractions from the ground up just so I can move the one-off behavior away from the abstraction. Ironically that almost always requires me to modify usages of the "reusable" code, which are spread across many files. Isn't that what we were trying to avoid?

It is my opinion that often times, duplicate code is the most maintainable solution. Not everything needs to be generic and extensible. Tools like Search & Replace All make it quite easy to identify duplicate code and modify it all in one click. But when you're faced with a bad abstraction, these tools can do nothing to help you fix the problem.