Rendering Rails Reuseless??

Normally I prefer trying to write an original text of my own; but in this case I can’t help but pass the word. This post thought the words out loud right out of my mouth: Reuse is vastly overrated, by Rails creator David Heinemeier Hansson. Quote:

Reuse only works well when the particular instances are so similar that you’re willing to trade the small differences for the increased productivity. That’s often the case for infrastructure, such as Rails, but rarely the case for business logic […]

I agree so wholeheartedly because I’ve seen so many counter-efficient examples of reuse in applications. Done by programmers twisting and tweaking their code to make reuse possible in the first place, and endlessly after to keep all the dependant code working when changes have to be made. Pray that the reusable code has been thoroughly documented if you are the one having to maintain it. You wouldn’t be the first to realize that rewriting might be faster than reinventing the reasoning behind the reusable code.

In our current (Java) project, we quickly found out that we were going to need a similar search popup throughout the application. Users wanted to search for different types of relations (clients, companies, partner companies, intermediaries, etcetera) in different usecases. So we made one generic, reusable popup that could find them all. Generic, because the search and result fields are parameterizable; only the calls to the backend business methods (that are not so generic) differ.
This setup worked fine until in one usecase an extra requirement was added for a two-level search: search a client, than select one of his insurance policies. We couldn’t “trade the differences for increased productivity”: the client usually gets what the client wants. We didn’t want to make such a large extension to the original popup code, because several usecases using that had already been tested and marked complete. So it was decided that we would pop out a new popup, which could still benefit from the original popup: much of the code could be ‘reused’, as in ‘duplicated’. After that, more specialized popups were soon to follow.
We still have a lot of uses for the original popup though, where the basic functionality is sufficient for that particular usecase. I guess it’s a case of knowing when to stop trying to be reusable and not be too afraid to duplicate some code if you have to. In a sense, rewriting sped up by duplicating existing code is just another form of code reuse.

2006-01-21. 2 responses.

Comments

  1. […] Danny Lagrouw has commented on a blog entry called Reuse is vastly overrated by David Heinemeier Hansson. Basically, the conclusion is that often reuse is simply not worth the struggle. […]

  2. I think the lesson is that reuse has its limits. Just think of all the time saved by using the basic popup functionality throughout the application, instead of focusing on the fact that one specialized popup had to be done. As with anything, it’s easy to go overboard with reuse.