The Art of Copying
By kto on Jul 10, 2006
The Art of Copying
We live in an age of copies, and this seems to have carried over into the software we develop. Have you ever reviewed some code, or scanned some software and thought "I know I have seen that code before!". Minus any copyrights, or comments documenting the origins of the code, odds are you are looking at copied code, and sometimes the origins of the code is contained in the same project where the copy is.
Shared libraries have been around for ages, but are we really taking advantage of them? How many programs and libraries have you seen that use static libraries? Using static libraries means that you have essentially 'copied' the code from one library into your own program or library. Why do people do that?
OO based programing languages are supposed to allow for better code sharing, but do we all take advantage of it? Seems like many C++/Java based projects tend to copy the source for a class and modify the class rather than extend and re-use the base class. Why is that?
Ignoring the legal aspects for the time being, and just for the sake of discussion, why do people do this? Aren't we just replicating all the existing bugs into many products?
I've heard lots of reasons why it's important to copy code, so I thought I would just list a few that I have heard:
I needed to change a class and
I don't have time to verify I haven't broken the other uses of a class.
So now the original is tested less.
There were bugs in the original, so I fixed the bugs in my copy.
And left everyone else with the buggy version.
I use a static link of my code because I don't trust the shared library to be stable.
And the copy of the unstable code you have is somehow better?
I need to have all the source to everything in my project.
What about the long term maintenance aspects to this? What about the source for the OS?
I don't have the time to structure the code right.
Seems like you just left the mess for someone else.
Everybody knows a staticly linked library will be faster.
You gotta get that 0.1% performance boost, nevermind the fact that you have just cloned a few dozen bugs into your code.
Our project needed some code fixed and we couldn't wait, so we copied all the
code and fixed the problem.
Now you have a support nightmare, did you plan on undoing this?
So what's your reason for copying code?