views:

74

answers:

2

I think copy/paste is one of the worst practices there could be in the industry.

Copy and paste code snippets it's ok. That's how most of the code is learn in first place, and saves a lot of time.

What is definitely harmful ( at least from my point of view ) is to copy one section of code from a class or file within THE SAME PROJECT!. Pieces of code that are perform almost the same thing, but that have subtle changes in one or two lines.

The problem comes when after a few months in production or still in beta, a change has to be introduced. Since they are not the same code, you cannot apply the same change, or for some reason the same patch doesn't seems to work ( until after a few hours, you realize, a intermediate call is performed or something like that )

While this is my feeling about the topic, I don't really know if there is an study about it, or something related.

Q.

Does anyone have a reference/paper/article/study or whatever talking about damage produced by copy/paste code?

Related:

http://stackoverflow.com/questions/401856/is-copy-and-paste-coding-ever-acceptable/401863 http://stackoverflow.com/questions/181549/how-often-do-you-make-errors-by-copying-and-pasting-code

A: 

Andy Hunt and Dave Thomas on the DRY principle

Sometimes I Repeat Myself

I recommend trying out a static analysis tool like CPD from PMD.

Instantsoup
Wow, didn't think this was worth a downvote!
Instantsoup
Well presumably no one would post an answer that they thought was worth a downvote. So if that were the criteria for downvoting, no one would ever get any.
EBGreen
True enough. A couple more downvotes and I can get a badge for deleting it!
Instantsoup
This only shows the number of duplications it doesn't show the damage produced by copy/paste code as was asked.
Daniel Moura
@Daniel I'd argue that it successfully "measure[s] the number of errors introduced by copy/pasting code?"
Instantsoup
@Instantsoup: On the grounds that having any copy-pasted code is an error, since while it might work now it's a maintenance disaster waiting to happen? I can sympathize with that.
David Thornley
+1  A: 

Here's an interesting discussion of the issue, with some colorful synonyms.

Jon B