Jump to content

Redundant code

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by SEIBasaurus (talk | contribs) at 00:53, 12 August 2010 (See also: Redundancy is required to transmit error free data in the presence of a noisy channel). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Redundant code is a computer programming term for code that computes a result that has been previously computed and is currently available, thus the repeated computation of the result is redundant.[1] If redundant code can be identified then it can be eliminated, reducing the overall computational cost of the program.

Example

 int f (int x)
 {
 	int y=x*2;
 	return x*2;
 }

The second x*2 expression is redundant code and can be replaced by a reference to the variable y. Alternatively the definition int y=x*2 can instead be removed.

Alternate uses of the term

The term redundant code may also be used to described code that has any form of redundancy, such as recomputing a value that has previously been calculated and is still available, code that is never executed, or a result which is executed and not used. Redundant code may also be used to refer to code that is executed but has no effect on the output of a program – however this is usually known as dead code. A NOP might be considered to be redundant code that has been explicitly inserted to pad out the instruction stream or introduce a time delay. Identifiers that are declared but never referenced are usually termed as redundant declarations.

See also

References