Copy and Paste Programming
What is copy and paste programming, why should it be avoided and why is it used?
Copy and Paste Programming – Reusing Existing Source Code
Source code that is used in identical form multiple times within an application is called a code duplicate – alternatively also a software clone or source code clone. The process that leads to the reuse of existing code is called copy and paste programming.
Copy and paste programming is a shortcut in software development and although there may be situational reasons for taking a shortcut, the process is rather frowned upon among software developers. Copied and pasted code is not a mark of quality in good software.
Reasons for copy and paste programming
- time pressure or time saving,
- risk minimisation,
- laziness or
- criminal energy.
Time pressure is probably the most common reason that leads to copy and paste programming. If developers lack time, they try to produce software as quickly and effectively as possible. A piece of source code that serves well in one place and facilitates implementation or testing of functions in another is therefore a welcome way to make rapid progress in development. If the pasted source code remains permanently at the new place of use, it should be adapted accordingly by renaming variables or deleting or adding lines of code.
Another reason for copying and pasting functions could be to avoid errors. Source code that “works” in one place can also work in another place – with appropriate adaptation – and thus minimise the risk of errors.
The third reason could be the ignorance of the developer. He may not understand the concrete functionality of some source code lines, but sees the desired effect and therefore copies the lines. Whether this reason is better in practice than the reason “laziness” with the underlying thought “Why should I bother to implement something new when I can use something existing” is probably in the eye of the beholder. From a “professional” perspective, both reasons are unacceptable.
And last but not least, there is “criminal energy” as a reason for copy and paste programming. Here again, “foreign” source code is copied from another application. This does not create a code duplicate, but since it may be illegal, this must not be accepted as a reason under any circumstances.
Impulse to discuss:
Can you think of other reasons for copy and paste programming?
Sometimes it is simply referred to as copy-paste programming.
Here you will find additional information from our Smartpedia section: