GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Main page
  • Contents
  • Current events
  • Random article
  • About Wikipedia
  • Contact us
  • Help
  • Learn to edit
  • Community portal
  • Recent changes
  • Upload file
  • Special pages
  • Search
  • Donate

This view

  • Original page
  • New address

GeezerVison is showing en.wikipedia.org — Redundant code - Wikipedia

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
Calculating again a value that has previously been calculated[1] and is still available.
Dead code
Code that is executed but has no external effect (i.e., does not change the output produced by a program).
Unreachable code
Code that is never executed (also called dead code).
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 second x * 2 expression is redundant code. Line 2 can be removed, or alternatively, line 3 can be changed to return y;.

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

A more subtle example involves the C preprocessor that inserts code before compilation. Consider:

#define min(A,B) ((A)<(B)?(A):(B))
int shorter_magnitude(int a, int b, int c, int d) {
    return sqrt(min(a*a + b*b, c*c + d*d));
}

After preprocessing, the code expands to code that evaluates both a*a + b*b and c*c + d*d twice. To eliminate the duplicate code, the macro min could be converted to a function.

int shorter_magnitude(int a, int b, int c, int d) {
    return sqrt(((a*a + b*b)<(c*c + d*d)?(a*a + b*b):(c*c + d*d)));
}

See also

  • Code bloat – Production of unnecessarily long, slow or wasteful program code
  • Code reuse – Using existing code in new software
  • Common subexpression elimination – Compiler optimization
  • Don't repeat yourself – Principle of software development
  • Duplicate code – Repeated fragment of computer source code
  • Redundancy (information theory) – Message encoded with more bits than needed
  • Code refactoring – Restructuring existing computer code without changing its external behavior
  • Code smell – Characteristic of source code that hints at a quality problem

References

  1. ↑ Debray, S. K., Evans, W., Muth, R., and De Sutter, B. 2000. Compiler techniques for code compaction. ACM Trans. Program. Lang. Syst. 22, 2 (Mar. 2000), 378–415.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Redundant_code&oldid=1372508587"
Categories:
  • Compiler optimizations
  • Software anomalies
  • Source code
Hidden categories:
  • Articles with short description
  • Short description is different from Wikidata
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.