Source Code Reuse
What are your thoughts on code reuse? Better yet, what are your experiences and lessons learned? In A Practical Guide to Enterprise Architecture (Coad Series), James McGovern, Scott W. Ambler, Michael E. Stevens, James Linn, Vikas Sharan, and Elias K. Jo write about source code reuse.
Reusing Code is Like Creating a Ransom Note from Newspaper Clippings
McGovern, Ambler, Stevens, Linn, Sharan, and Jo write the following:
Software reuse is usually identified with the reuse of source code across software systems. Source code is extremely difficult to reuse on a large scale. The software development community has tried and mainly failed to reuse source code. Bob Frankston, a programmer from VisiCalc, the first spreadsheet program, had this to say (Wired 2002):
“You should have huge catalogs of code lying around. That was in the 70′s; reusable code was the big thing. But reusing pieces of code is like picking off sentences from other people’s stories and trying to make a magazine article.”
While you can write a magazine article using sentences from other works, it is a little like creating a ransom note from newspaper clippings. You might make your point, but not very clearly. It is usually easier to just write the whole code yourself. Direct source code reuse is extremely difficult, and, as a result, has mostly failed to materialize, even with the invention of OOP in the 1990′s.
Key Take Aways
Here’s my key take aways:
- Reusing code on a large scale is difficult.
- Direct reuse can be extremely difficult.
- Sometimes you are better off writing the code from scratch.
Back at Work
I think the key distinctions in here are direct reuse and large scale. There’s many ways to get the benefit of reuse beyond the direct code, such as through patterns. Also, I’ve found that fine-grained components or services that do one thing well, are great reuse candidates (for example, data access blocks, caching blocks, logging blocks, … etc.)
- Code Reuse (Wikipedia)