FACTOID # 102: Kids in Mali spend only 2 years in school. More than half of them start working between the ages of 10 and 14.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Unreachable code

Contents

In computer programming, unreachable code, or dead code, is code that exists in the source code of a program but can never be executed. “Programming” redirects here. ... Source code (commonly just source or code) is any series of statements written in some human-readable computer programming language. ...


Dead code is generally considered undesirable for a number of reasons, including:

  • If the author of the code intended the code to be executed, then there is a bug in the program.
  • If the author and maintainers of the code have overlooked the fact that it will never be executed, then time and effort may be wasted on maintaining it.

Redundant code is code that is executed but has no effect on the output from a program. Identifiers that are declared but never referenced are not included in this definition and usually go by another name such as redundant declaration. A software bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from behaving as intended (e. ... Redundant code is a computer programming term for code that is executed but has no effect on the output of a program (dead code is the term applied to code that is never executed). ...


Detecting dead code

Detecting dead code is a form of static analysis and involves performing control flow analysis to find any code that will never be executed regardless of the values of variables and other conditions at run time. In some languages (e.g. Java) unreachable code is explicitly disallowed. Naturally enough, the optimization that removes dead code is known as dead code elimination. This article is about the statistical technique. ... In computer science control flow (or alternatively, flow of control) refers to the order in which the individual statements, instructions or function calls of an imperative or functional program are executed or evaluated. ... “Java language” redirects here. ... Dead code elimination is a technique used in computer science to reduce program size by removing code which can never be executed. ...


Code may become dead as a consequence of the internal transformations performed by an optimizing compiler (e.g., common subexpression elimination). There are probably other specialized domains that also make use of this term. Compiler optimization techniques are optimization techniques that have been programmed into a compiler. ... In compiler theory, common subexpression elimination (CSE) is the practice of finding repeated redundant expression evaluations, and replacing them with a single computation assigned to a temporary variable. ...


Reasons unreachable code is created

The following are some of the reasons why unreachable code may exist in source code.


During software development some programmers temporarily disable code (ie, insert constructs that prevent it being ever executed). For example, in the following code:

 while (condition) { foo(); bar(); } 

If we wish to temporarily disable the functionality of bar() (possibly several lines of code), a quick hack would be: A hack in progress in Lobby 7 at MIT. Hack is a term in the slang of the technology culture which has come into existence over the past few decades. ...

 while (condition) { foo(); continue; bar(); } 

In this example, bar() has become unreachable code (since continue means run the next iteration of the loop immediately instead of at the end of the loop). Unfortunately, sometimes changes that are intended as temporary make their way into the release version. A software release refers to the creation and availability of a new version of a computer software product. ...


Other sources of unreachable code include redundant checking of exception conditions, and debugging code which has yet to be removed. Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. ...


Complete functions may not be executed as they are no longer called (presumably the reason why they were written is that they used to be called), or are called only from unreachable code.


The presence of unreachable code may reveal either logical errors due to alterations in the program or significant changes in the assumptions and environment of the program (see also software rot); a good compiler should report dead code so a maintainer can think about what it means. Software rot, also known as code rot or software decay, is a type of bit rot. ...


Detecting unreachability

Determining whether an arbitrary piece of code is unreachable code is equivalent to solving the halting problem. This means that it is not possible to correctly locate unreachable code in all cases. In computability theory the halting problem is a decision problem which can be informally stated as follows: Given a description of a program and a finite input, decide whether the program finishes running or will run forever, given that input. ...


In practice the sophistication of the analysis performed has a significant impact on the amount of unreachable code that is detected. For example, constant folding and simple flow analysis shows that the statement xyz in the following code is unreachable:

 int n = 2 + 1; if (n == 4) { xyz } 

However, a great deal more sophistication is needed to work out that in the following code:

 double x = sqrt(2); if (x > 2) { xyz } 

the statement xyz is unreachable.


Unreachability vs. profiling

In some cases, a practical approach may be a combination of simple unreachability criteria and use of a profiler to handle the more complex cases. Profiling in general can not prove anything about the unreachability of a piece of code, but may be a good heuristic for finding potentially unreachable code. Once a suspect piece of code is found, other methods, such as a more powerful code analysis tool, or even analysis by hand, could be used to decide whether the code is truly unreachable. In computer programming, a profiler is a computer program that can track the performance of another program by checking information collected while the code is executed . ... Look up Heuristic in Wiktionary, the free dictionary. ...


See also


  Results from FactBites:
 
Compiler optimization - Wikipedia, the free encyclopedia (3471 words)
Also, debugging code is usually stepped through in a symbolic debugger, and optimizing transformations, particularly those that reorder code, can make it difficult to identify the output code with the line numbers in the source code from which the code was generated.
Pieces of code executed close together in time should be placed close together in memory, which increases spatial locality of reference.
When some code invokes a procedure, it is possible to directly insert the body of the procedure inside the calling code rather than transferring control to it.
ORBSEARCH.COM | encyclopedia of knowledge (3007 words)
Code optimization usually starts with a rethinking of the algorithm used in the program: more often than not, a particular algorithm can be specifically tailored to a particular problem, yelding better performance than a generic algorithm.
Thus code optimizations should be carefully documented and their effect on future development evaluated.
Dead code refers to code segments which can never be executed.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.