Simon Harriyott

How reusable is reuse?

Had a discussion yesterday with a couple of colleagues about using somebody else's code. This all started after I had agonised over a design problem, and come up with a nifty solution, and written it in the spec. One of the others said something like "Half of that seems to be like some of this Microsoft application block, maybe we should use that."

So I spent all morning looking at the application block, trying to work out what it did, and what the generic terms actually meant. To use this application block in our application would have meant taking out some of it, and adding something else to it. I suggested that this wasn't really "reuse", as it changed the meaning of the original code. This was countered with the point that if the code has been written already, why rewrite it?

Having slept on it, it seems that the two extremes of reuse are:
  1. This existing code does exactly what we need, so we'll use it.
  2. This existing code does the opposite of what we need, in a different language, and on a different platform, so we won't use it.
I reckon most reuse "candidates" lie somewhere between the two. There's a point at which something reusable becomes more trouble than it's worth. If it requires too much changing, then it solves a different problem than it was being considered for. If the existing code or design requires too much changing to use it, then using it is upsetting the original purpose of the project.

On the other hand, if the code inside the module is well written, and easy to read and understand, it may be a trivial task to bend it into the exact requirement. Identifying quite where the tipping point is involves the skill of a talented developer.

The exception handling application block (in the context of my current project) seems to be extreme number 1, which is fantastic. It just does it. Include the assembly, set up the config file, and add a line of code in the catch block. Bish bash bosh. This is what I would call "reuse". I'm not sure what to call stuff between this extreme and the tipping point though. What is the maximum amount of change a code module can undergo and still be considered "reusable"?
17 February 2005