Copy and paste programming
|
Copy and paste programming is an informal computer programming style that simply copies code from one program to another. It is generally criticized as a bad practice or an anti-pattern. The term is in conjecture with a common activity in computing, copy and paste.
Copy and pasting is often done by inexperienced or student programmers, who find the act of writing code from scratch difficult and prefer to search for a pre-written solution or partial solution they can use as a basis for their own problem solving. The problem in this approach lies with the fact that the inexperienced programmers do not fully understand the pre-written code they are taking. The code often comes from disparate sources such as friends or co-worker's code, Internet forums, code provided by students' professors/TAs and computer science textbooks. The result is invariably a disjointed clash of styles and often has superfluous code that tackles problems for which solutions are no longer required. Bugs can also easily be introduced by assumptions and design choices made in the separate sources that no longer apply when placed in a new environment.
Copy and pasting is also done by experienced programmers, who often have their own libraries of well tested, ready-to-use code snippets and generic algorithms that are easily adapted to specific tasks. However, adherents of object oriented methodologies claim that this form of programming is still wrong. Instead of making multiple, mutated copies of a generic algorithm, the algorithm should be written as a reusable class and should be written so flexibly that all new code can be interfaced to use this generic code directly, rather than mutate the original. This way, if the original algorithm has a bug to fix or can be improved, all software using it stands to benefit and the programmer does not need to hunt down each and every instance of the code.
Use of programming idioms and design patterns are distinct from copy and paste programming, as they are expected to be recalled from the programmer's mind, rather than retrieved from a code bank.