1. Home
  2. Smartpedia
  3. Copy and Paste Programming

What is Copy and Paste Programming?

Smartpedia: Copy and paste programming refers to the copying and pasting, and thus the reuse, of source code, usually within an application.

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

There are several reasons that lead to copy and paste programming and the creation of code duplicates and code smells:

  • time pressure or time saving,
  • risk minimisation,
  • ignorance,
  • 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.

Copy and Paste Programming

Impulse to discuss

Can you think of other reasons for copy and paste programming?

Notes:

Sometimes it is simply referred to as copy-paste programming.

If you like the article or would like to discuss it, please feel free to share it in your network. And if you have any comments, please do not hesitate to send us a message.

What does t2informatik do?

Was does t2informatik do? One click and you'll know it.

Here you will find additional information from our Smartpedia section:

Smartpedia: What is Clever Code?

What is Clever Code?

Smartpedia: How does Refactoring work?

How does Refactoring work?