User Tools

Site Tools


principles:fail_fast

Fail Fast (FF)

Variants and Alternative Names

  • Rule of Repair1)
  • Crash Early2)

Context

Principle Statement

A design is better when fails fast, i.e. as soon as an unrepairable erroneous condition is encountered.

Description

Check for erroneous conditions like wrong parameter values, unmet preconditions, violated invariants, etc. In case of methods this means that it checks for errors and reports them for example by means of throwing an exception.

Rationale

When a failure remains undetected, it propagates through the system ultimately causing other modules to fail. This results in in a more complicated fault removal. Furthermore undesired side effects like corrupted files may occur. A crashed program clearly communicates that there is a problem and is often a better situation than a misbehaving program.

Strategies

  • Check input parameters for validity – especially non-nullness.
  • Throw an Exception.
  • Use assertions.

Caveats

FF reveals problems which are already present in the system. For a system with only a few problems, this is good as the remaining faults are identified and fixed more easily. But applying FF to a system that has many problems may decrease reliability further as problems which were hidden, show up, produce error messages and lead to system aborts.

See also section contrary principles.

Origin

Evidence

Relations to Other Principles

Generalizations

Specializations

Contrary Principles

Complementary Principles

  • Postel's Law: While FF is (amongst others) about checking for erroneous parameters, Postel's Law is about not being too strict with parameters. It says that the design should allow for uncommon or strangely arranged (yet meaningful) input data. This does not contradict FF as Postel's Law does not demand to process meaningless or erroneous data.
  • Principle of Least Surprise (PLS): FF is about what a module should do in the case of error. PLS on the other hand is about how the module should behave normally. Furthermore it normally is not a surprise that a module fails when there is an error but a module that doesn't fail when it should, behaves strangely.
  • Murphy's Law (ML): Even better than failing fast is to make errors logically impossible. ML is about this.

Principle Collections

Examples

Description Status

Further Reading

Discussion

Discuss this wiki article and the principle on the corresponding talk page.

2)
Andrew Hund and David Thomas The Pragmatic Programmer, p. 120
principles/fail_fast.txt · Last modified: 2015-11-12 20:13 by 24.224.252.66