Jump to content

Code duplication

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Quuxplusone (talk | contribs) at 06:56, 23 December 2006 (merge from Duplicate code and expand). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Code duplication is a computer programming or software engineering term for a sequence of source code that occurs more than once in a given program or collection of related programs. Code duplication makes maintenance and modification of source code harder, because if a change needs to be made to a duplicated line of code, then the same change usually needs to be made in all the places where that line was duplicated.

One common cause of code duplication in software projects is so-called copy and paste programming, in which a section of code is copied "because it works", without thinking about how the code could be refactored to allow a single code section to be reused, instead of duplicated.

The usual solution is to encapsulate the duplicated code into a library subroutine (which is modifiable) or a software component (which is not).

A number of different methods have been proposed to detect duplicate code automatically, with or without human intervention.

See also