A Rant on Reuse

Filed under: Uncategorized — anselor at 10:12 pm on Wednesday, March 23, 2005

In the world of computer science there are always new buzzwords coming in and out of vogue. Some of you may have heard of some of these: Java, Web, E-[insert anything here], object oriented.

A really cool word right now is ‘Reuse.’ This is a natural progression after the object oriented craze swept through. The only problem, as I see it, is the misuse/misapplication of the term reuse.

First, let us talk a little bit about what reuse means outside of software. When you buy a used car, you’re reusing the car. You would expect, in reusing a car that you would be able to just hop in the driver’s seat and go without modification to how the car functions or reconstructing the car from a pile of pieces. Going down to a lower level, say you tore up your passenger seat somehow. You go to the junk yard and pick up a passenger seat you can reuse. You might have to pick up some new bolts or screws to connect the reused seat to your car, but the idea is the seat requires no modification.

The term ‘Reuse’ implies there is no modification to the thing you’re reusing. You don’t need to know how it works, only what it does.

In software, you’ll often hear people talking about reusing code. What this means is they find various blocks of code embedded in some existing application, copy it out, and paste it somewhere inside their source. They then modify the code to compile correctly and test to make sure it is functioning correctly. Using the car analogy, this is like going to the junkyard and picking up pieces of cars and piecing it together. Would you say this is reusing an old car or re-engineering one?

Code reuse does not mean you should be copying source code and stuffing it in your program. Code reuse means the logic you want to reuse was designed to be a modular component you can drop in and reference without knowledge of how it works inside. If you’re modifying the old code you’re not reusing old code, you’re rengineering old code.

The key point here is that the reused component must be designed to be reused. In the example of the passenger seat, the seat had to be designed to be a stand-alone modular component. If the car’s frame and the passenger seat were formed out of a single solid chunk of metal, the passenger seat wouldn’t be reusable. To try and ‘reuse’ the seat would require you to cut out the seat and try to weld it into your car. More likely than not you’ll end up with an ugly chair welded into your car with questionable stability. You’d also not be able to remove it without a significant engineering effort. ‘Reusing’ old code that was not designed with reuse in mind creates an unstable unmaintainable product. Writing software without reuse in mind results in duplicated code, duplicated effort, and duplicated mistakes. In the event of a bug in a piece of ‘reused’ code, it has to be fixed in each place it was copied instead of in one place that’s reused by multiple people.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>