Copy paste is dangerous

When writing code, there's often a temptation to simply copy existing code, and paste it somewhere new. You might use the copied code as is, or you might change a part of it. In both cases, this kind of copy-paste coding is dangerous. It should almost always be avoided. The problem is that it violates the Don't Repeat Yourself rule. This rule is violated even if you modify a part of the copied code: the unmodified parts of the code remain duplicated.

You should almost never duplicate code if you can avoid it. If, in the future, some new change needs to be made to the repeated code, you'll have to manually find all instances of that code. Will you remember where to find all of those instances? In some cases yes, but in many cases no.

With regard to repeated code, an experienced programmer will:

Instead of simply copying code, you should use your design skills and experience to think about how to remove all code duplication. It's always possible to remove it, by refactoring the code into an improved implementation.