Redundant code
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.
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. [citation needed]
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
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. [citation needed]