Copy And Edit Revisited

Published

July 16, 2010

Vadim reminds me that I need to address root causes of Copy-Paste-Edit programming, rather than merely ranting about how bad a practice it is and how it ruins good code. Of course, he is right. That is part of being Vadim.

I’ve previously ranted about the ill-effects of copy-paste-edit programming, but it would be unfair to say that there is never a need for it, or that people who did it were simply stupid and lazy.  The problem would not be so prevalent if it did not have some reasonable basis for practice. However well-intentioned and useful it is, its net effect on a code base is overwhelming negative.

Here are a few root causes I recognize, and I’m open to hear more.
Is copying always wrong? I think it is not.  The act of copying itself should kick in your “spider sense,” but it is not necessarily harmful.  Copying examples from outside the system might be useful as a starting point.  Copying code from inside the system (including copying an existing test to help create a new test) can be helpful to the programmer.  However, having duplicated code in the system is always wrong, and having code that is placed badly is wrong as well.

It could be useful to put some rules around your use of copying.

Everything I said about the evils of copying code still stand.  If you copy a block of code, you are probably going to screw over your whole development organization a little (especially when the system changes and your original is no longer correct).  Copy-Edit is still the way to make a bloated mess of your system.