What Code Reuse Really Means
Tuesday, May 23rd, 2006Code reuse in software development is something assumed literally through re-using bits of code in more than one place. It is truly achieved through using common libraries and interfaces accessible to both the entire application and to other applications in the domain.
What is code reuse?
Literal definition: Code reuse is the practice of using existing code…again. There are some benefits and drawbacks to code reuse as it is defined here. If you take the literal meaning of the terms you end up with simply using what you’ve got in another place.
Benefits
- Speed – I tell you what, I can copy/paste stuff like no other. My fingers can instinctively assume the copy/paste position on near any keyboard shape w/o me even realizing it.
- Easy – there’s not really much thought involved in having to just duplicate your code in another applicable area of the application, or in another application. If it works in one place, it’s more than likely going to work just fine somewhere else.
Drawbacks
- Maintenance nightmare – if for any reason you want to change a copied section, you have to change ALL the copies.
- Unorganized – there isn’t much organization to it. You simply create massive amounts of code to decipher after a while.
So, if there’s such a possible mess after massive code reuse, what’s all the hype about? Companies are pushing for code reuse, yet it doesn’t seem to lend itself well to long term maintenance, which is the majority of the time spent on any lasting application.
More realistic definition: Code reuse is allowing code that you’ve written to be accessible from more than one place. It can also imply that as a component, it’s accessible via a common interface to other components or applications. Though this may not be the best 2-line definition of the term, the key is that it’s far more meaningful than the literal definition. The following sections elaborate more on what code reuse really is.