1. Home
  2. Smartpedia
  3. Dead Code

What is Dead Code?

Smartpedia: Dead Code is a term for lines of code that are not executed or whose results are not used after execution.

Dead Code – lines of code that are not executed

The term dead code is used in software development to describe lines of code that are not executed or whose results are not used after execution. Lines of code are not executed because they

  • are no longer needed,
  • are not called,
  • cannot be called.

Forms of Dead Code

Some publications differentiate between different forms of dead code:

  • Dead code exists when, for example, the result of a function is never used.
  • Redundant code exists when several lines of code do the same thing. If lines of code are unintentionally redundant, the redundancy should be removed. However, if the redundancy is intended, e.g. when temporarily preserving lines of code, it can be retained – at least temporarily.
  • Unattainable code occurs when lines of code cannot be called, e.g. because a condition of another line, which always occurs, prevents this.
  • Unnecessary code occurs when, for example, a query is formulated in such a way that the result is always true. The query therefore makes no sense.

Reasons for Dead Code

Dead code can arise for different reasons: A developer may have forgotten to delete superfluous lines of code. Or the developer has decided not to delete because the code is mixed with functional code. Or the code is intentionally not removed, so it can be reactivated at a later time. Or a programming error has been overlooked, etc.

Dead code in itself does not affect the execution of program parts. Since many developments in practice have to deal with “living” but faulty, functionally insufficient or non-performing code, Dead Code often only gets a low priority. Nevertheless, it should be avoided for various reasons:

  • it does not offer any benefit, but it may cause costs and effort if it is adapted in the course of further development.
  • It makes maintenance and support more difficult if it cannot be identified beyond doubt as dead, redundant, unattainable or unnecessary code. A refactoring could provide a remedy.
  • it increases the memory requirement.
  • it has an impact on code coverage, either because it is tested unnecessarily, or because it is not tested, it provides poor coverage.

In principle, it is therefore recommended to identify and eliminate dead code at an early stage. The corresponding term is: Dead Code Elimination.

Dead Code - lines of code that are not executed

What does t2informatik do?

Was does t2informatik do? One click and you'll know it.

Notes:

Here you will find additional information from our Smartpedia section:

Smartpedia: What is Clean Code?

What is Clean Code?

Smartpedia: What is Shadow IT?

What is Shadow IT?