Copy And Paste Is Nota Design Pattern

Recently, I was working on a project that started with existing code. There was obvious CopyAndPaste applied to huge chunks of code, over and over.

The real problem stems from what happens after the code is pasted. Oh, there just needs to be a minor change here or there to hook this code into the surroundings. Oh, and over the years, a minor change is made here and there.

At first, this doesn't seem like the worst coding offense in the world. The real problem comes in when you try to fix and/or merge this code, possibly 5-10 years later.

So, along comes someone else trying to fix something in one instance of this code. Then they realize there is another instance of the code, and another, and ... Trying to find the duplicated code and perform EliminateDuplication can lead to mutiny, particularly when the code is extremely similar, but no longer exactly the same. This is what is referred to as CodeMaintenanceNightmare?.

-- JasonNocks

See also CopyAndPasteProgramming.


It's an AntiPattern

Heh! Nice illustration. I've a mind to copy this into CopyAndPasteIsAnAntiPattern?.


CategoryAntiPattern



Recently, I was working on a project that started with existing code. There was obvious CopyAndPaste applied to huge chunks of code, over and over.

The real problem stems from what happens after the code is pasted. Oh, there just needs to be a minor change here or there to hook this code into the surroundings. Oh, and over the years, a minor change is made here and there.

At first, this doesn't seem like the worst coding offense in the world. The real problem comes in when you try to fix and/or merge this code, possibly 5-10 years later.

So, along comes someone else trying to fix something in one instance of this code. Then they realize there is another instance of the code, and another, and ... Trying to find the duplicated code and perform EliminateDuplication can lead to mutiny, particularly when the code is extremely similar, but no longer exactly the same. This is what is referred to as CodeMaintenanceNightmare??.

-- JasonNocks

Hah! Nice demonstration. I've a mind to paste this into CopyAndPasteIsntaDesignPattern?.

See also CopyAndPasteProgramming.

It's an AntiPattern


EditHint: There are multiple copy-and-paste topics floating around. Perhaps it is time for consolidation.


CategoryAntiPattern


EditText of this page (last edited November 1, 2005) or FindPage with title or text search