FACTOID # 11: The USA has more personal computers than the next 7 countries combined.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Code duplication

Duplicate code is a computer programming term for a sequence of source code that occurs more than once in a program. A minimum requirement is usually applied to the quantity of code that must appear in a sequence for it to be considered duplicate rather than coincidentally similar. Computer programming (often shortened to programming or coding) is the process of writing, testing, and maintaining the source code of computer programs. ... Source code (commonly just source or code) is any series of statements written in some human-readable computer programming language. ...


Sequences of duplicate code are sometimes known as clones.


The following are some of the ways in which two code sequences can be duplicates of each other:

  • character for character identical
  • character for character identical with white space characters and comments being ignored
  • token for token identical
  • functionally identical

Contents

How duplicates are created

There are a number of reasons why duplicate code may be created, including:

  • Copy and paste programming, in which a section of code is copied "because it works".
  • Functionality that is very similar to that in another part of a program is required and a developer independently writes code that is very similar to what exists elsewhere.
  • Plagiarism, where code is simply copied without permission or attribution.

Copy and paste programming is an informal computer programming style that simply copies code from one program to another. ... Plagiarism is the unauthorized use or close imitation of the language and thoughts of another author and the representation of them as ones own original work. ...

Detecting duplicate code

A number of different algorithms have been proposed to detect duplicate code:

  • Baker's paper
  • Swiss work on visual clone detection
  • other people

Example of functionally duplicate code

Consider the following code snippet for calculating the average of an array of integers It has been suggested that this article or section be merged with Snippet management. ... In mathematics, an average or central tendency of a set (list) of data refers to a measure of the middle of the data set. ... This article or section does not cite its references or sources. ... The integers are commonly denoted by the above symbol. ...

 extern int array1[]; extern int array2[]; int sum1 = 0; int sum2 = 0; int average1 = 0; int average2 = 0; for (int i = 0; i < 4; i++) { sum1 += array1[i]; } average1 = sum1/4; for (int i = 0; i < 4; i++) { sum2 += array2[i]; } average2 = sum2/4; 

The two loops can be rewritten as the single function:

 int calcAverage (int* Array_of_4) { int sum = 0; for (int i = 0; i < 4; i++) { sum += Array_of_4[i]; } return sum/4; } 

See also

Dont Repeat Yourself (DRY, also known as Once and Only Once or Single Point of Truth (SPOT)) is a process philosophy aimed at reducing duplication, particularly in computing. ...

External links


  Results from FactBites:
 
Technology, Dynamic Programming and Entrepreneurship (5146 words)
Cut and paste coding causes problems because logic is duplicated all over the place.
Unfortunately there is a lot of code written on top of the structure and very little political support for rebuilding it.
People do want bug free code, and perhaps they don't want to pay any more for it, but as long as we can get free software that is more secure and more bug free than software that costs hundreds of dollars, people will continue to defect to open source.
architectures of participation « Into The Pudding (9175 words)
Just as source code is a number of small files that fit together to make a program, so too does geographic data (points, lines, polygons) fit together to make a map.
The ‘instructions’ in the case of geodata are not the human readable source code, but instead the raw data that can be used to make maps.
It’s the last task that they’re excited about doing, it’s similar to how coders don’t like to comment their code, but it’s even worse, since there are arcane standards that require ‘training‘.
  More results at FactBites »


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m