Dead code

Dead code

Dead code is a computer programming term for code in the source code of a program which is executed but whose result is never used in any other computation.[1][2] The execution of dead code wastes computation time as its results are never used.

While the result of a dead computation may never be used the dead code may raise exceptions or affect some global state, thus removal of such code may change the output of the program and introduce unintended bugs. Compiler optimizations are typically conservative in their approach to dead code removal if there is any ambiguity as to whether removal of the dead code will affect the program output.

Contents

Example

int f (int x, int y)
{
        int z=x+y;
        return x*y;
}

In the above example the sum of x and y is computed but never used. It is thus dead code and can be removed.

public void Method(){
    final boolean debug=false;
 
    if (debug){
      //do something...
    }
}

In the above example "do something" is never executed, and so it is dead code.

Analysis

Dead code elimination is a form of compiler optimization in which dead code is removed from a program. Dead code analysis can be performed using live variable analysis, a form of static code analysis and data flow analysis. This is in contrast to unreachable code analysis which is based on control flow analysis.

The dead code elimination technique is in the same class of optimizations as unreachable code elimination and redundant code elimination.

In large programming projects, it is sometimes difficult to recognize and eliminate dead code, particularly when entire modules become dead. Test scaffolding can make it appear that the code is still live, and at times, contract language can require delivery of the code even when the code is no longer relevant.[3]

See also

References

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • dead code — noun a) instructions that, when executed, have no effect on the running of the program. Many software projects contain much dead code in the form of deprecated functions. b) code that exists in the source, but that will never be executed …   Wiktionary

  • Dead code elimination — (englisch für Entfernung von totem Code) ist ein Verfahren aus dem Bereich des Compilerbaus, das nicht verwendete Anweisungen beseitigt. Dadurch kommt es zu einem kleineren Programm mit schnellerer Ausführung. Erläuterung mit Beispielen Gegeben… …   Deutsch Wikipedia

  • Dead code elimination — In compiler theory, dead code elimination is a compiler optimization to remove code which does not affect the program results. Removing such code has two benefits: it shrinks program size, an important consideration in some contexts, and it… …   Wikipedia

  • dead code — ● ►en /daid kod/ loc. m. ►PROG Voir code mort …   Dictionnaire d'informatique francophone

  • War Games 2: The Dead Code — Filmdaten Deutscher Titel War Games 2: The Dead Code Originaltitel Wargames: The Dead Code …   Deutsch Wikipedia

  • Code bloat — is the production of code that is perceived as unnecessarily long, slow, or otherwise wasteful of resources. Code bloat can be caused by inadequacies in the language in which the code is written, inadequacies in the compiler used to compile the… …   Wikipedia

  • code mort — ● loc. m. ►PROG code qui ne sera jamais atteint dans le déroulement d un programme. La présence de code mort révèle une erreur logique dans un programme ou des changements significatifs dans son environnement. Un bon compilateur doit le signaler …   Dictionnaire d'informatique francophone

  • dead — ● ►en adj. ►ARGOT mort. Voir aussi dead code (code mort). Rarement utilisé en français …   Dictionnaire d'informatique francophone

  • Code of Vengeance — Title card for the 1985 TV movie Also known as Dalton and Dalton s Code of Vengeance Genre …   Wikipedia

  • Dead or Alive: Code Chronos — Developer(s) Team Ninja Publisher(s) Tecmo Designer(s) Tomonobu Itagaki …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”