ArticleslgStudy

computer science

Heisenbug

Heisenbug is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Heisenbug rather than just read about it. In short: In computer programming jargon, a heisenbug is a software bug that seems to disappear or alter its behavior when one attempts to study it. The term is a pun on the name of Werner Heisenberg, the physicist who first introduced the uncertainty principle, and it is a reference to the observer effect, which states that the act of observing a system inevitably alters its state.

Key takeaways

  • Heisenbug belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Heisenbug to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Heisenbug from memory before moving on to harder problems.

Reference excerpt

In computer programming jargon, a heisenbug is a software bug that seems to disappear or alter its behavior when one attempts to study it. The term is a pun on the name of Werner Heisenberg, the physicist who first introduced the uncertainty principle, and it is a reference to the observer effect, which states that the act of observing a system inevitably alters its state. In electronics, the traditional term is probe effect, where attaching a test probe to a device changes its behavior. The term has been criticized because it confuses Heisenberg's uncertainty principle (to which it owes the name) with the observer effect in quantum mechanics, which are distinct concepts. Similar terms, such as "bohrbug", "mandelbug", "hindenbug", and "schrödinbug" (see the section on related terms) have been occasionally proposed for other kinds of unusual software bugs, sometimes in jest.

Examples Heisenbugs occur because common attempts to debug a program, such as inserting output statements or running it with a debugger, usually have the side-effect of altering the behavior of the program in subtle ways, such as changing the memory addresses of variables and the timing of its execution. One common example of a heisenbug is a bug that appears when the program is compiled with an optimizing compiler, but not when the same program is compiled without optimization (as is often done for the purpose of examining it with a debugger). While debugging, values that an optimized program would normally keep in registers are often pushed to main memory. This may affect, for instance, the result of floating-point comparisons, since the value in memory may have smaller range and accuracy than the value in the register. Similarly, heisenbugs may be caused by side-effects in test expressions used in runtime assertions in languages such as C and C++, where the test expression is not evaluated when assertions are turned off in production code using the NDEBUG macro. Other common causes of heisenbugs are using the value of a non-initialized variable (which may change its address or initial value during debugging), or following an invalid pointer (which may point to a different place when debugging). Debuggers also commonly allow the use of breakpoints or provide other user interfaces that cause additional source code (such as property accessors) to be executed stealthily, which can, in turn, change the state of the program. End-Users can experience a heisenbug when the act of making a screenshot of the heisenbug for observation fixes the heisenbug and the screenshot shows a perfectly working state. This effect can happen when complex stacks of software work together, for example a web browser using a hardware graphic card acceleration which causes rendering errors on the physical screen that do not show on a screenshot. Time can also be a factor in heisenbugs, particularly with multi-threaded applications. Executing a program under control of a debugger can change the execution timing of the program as compared to normal execution. Time-sensitive bugs, such as race conditions, may not occur when the program is slowed down by single-stepping source lines in the debugger. This is particularly true when the behavior involves interaction with an entity not under the control of a debugger, such as when debugging network packet processing between two machines and only one is under debugger control. Heisenbugs can be viewed as instances of the observer effect in information technology. Frustrated programmers may humorously blame a heisenbug on the phase of the moon, or (if it has occurred only once) may explain it away as a soft error due to alpha particles or cosmic rays affecting the hardware, a well-documented phenomenon known as single event effects.

Related terms A bohrbug, by way of contrast, is a "good, solid bug". Like the deterministic Bohr atom model, they do not change their behavior and are relatively easily detected. A mandelbug (named after Benoît Mandelbrot's fractal) is a bug whose causes are so complex it defies repair, or makes its behavior appear chaotic or even non-deterministic. The term also refers to a bug that exhibits fractal behavior (that is, self-similarity) by revealing more bugs (the deeper a developer goes into the code to fix it the more bugs they find). A schrödinbug or schroedinbug (named after Erwin Schrödinger and his thought experiment) is a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place. A hindenbug (named after the Hindenburg disaster) is a bug with catastrophic behavior. A higgs-bugson (named after the Higgs boson particle) is a bug that is predicted to exist based upon other observed conditions (most commonly, vaguely related log entries and anecdotal user reports) but is difficult, if not impossible, to artificially reproduce in a development or test environment. The term may also refer to a bug that is obvious in the code (mathematically proven), but which cannot be seen in execution (yet it is difficult or impossible to find in practice).

Etymology The earliest known appearance is from 1983, in an ACM publication. The term was used in 1985 by Jim Gray, in a paper about software failures, and is sometimes mistakenly attributed to him because of this publication. It was used in 1986 by Jonathan Clark and Zhahai Stewart on the mailing list (later Usenet news group) comp.risks. Bruce Lindsay, a researcher at IBM, affirmed in a 2004 ACM Queue interview that he was present when the Heisenbug was originally defined, but did not state when this occurred.

Resolution Heisenbugs are difficult to identify and fix; often attempting to resolve them leads to further unexpected behavior. Because the problem manifests as the result of a separate, underpinning bug, the behavior can be hard to predict and analyze during debugging. Overall the number of heisenbugs identified should decrease as a piece of software matures.

See also Cargo cult programming Jinx Debugger—a tool that automatically explores executions likely to expose Heisenbugs Memory debugger

References

External links The Heisenberg Debugging Technology A Story About Magic OpenOffice won't print on Tuesdays, a heisenbug that took almost nine months to solve.

Worked examples

Example 1 — a first encounter with Heisenbug

Start with the simplest possible case. Write down what Heisenbug claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Heisenbug before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Heisenbug ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Heisenbug

In research
Heisenbug appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Heisenbug in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Heisenbug is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer jargon, Computer programming folklore, Debugging, so understanding it makes those chapters shorter.
In everyday life
Look for Heisenbug outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Heisenbug” →

How to study Heisenbug in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Heisenbug means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Heisenbug out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Heisenbug in simple terms?

In computer programming jargon, a heisenbug is a software bug that seems to disappear or alter its behavior when one attempts to study it. The term is a pun on the name of Werner Heisenberg, the physicist who first introduced the uncertainty principle, and it is a reference to the observer effect…

Why does Heisenbug matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Heisenbug?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Heisenbug.

Tags

  • Computer jargon
  • Computer programming folklore
  • Debugging
  • Software bugs
  • Software engineering folklore
  • Software testing

Keep exploring