Redundant code
In computer programming, redundant code is source code or compiled code that is unnecessary. Code that can be removed without affecting its desired behavior is redundant.
Categories
Notable categories of redundant code include:; Recomputing: Recomputing a value that has previously been calculated and is still available.
; Dead code: Code that is executed but has no external effect.
; Unreachable code: Code that is never executed.
; NOP padding: A NOP instruction might be considered redundant if it is for padding. But if the NOP is required for proper functionality, then it is not redundant.
; Unused identifier: Something declared, but never referenced, is a redundant declaration.
Examples
In the following C code, the secondx * 2 expression is redundant code. Line 2 can be removed, or alternatively, line 3 can be changed to.int foo
A more subtle example involves the C preprocessor that inserts code before compilation. Consider:
- define min
After preprocessing, the code expands to code that evaluates both and twice. To eliminate the duplicate code, the macro could be converted to a function.
int shorter_magnitude