In programming language theory, lazy evaluation or call-by-need is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (sharing). The sharing can reduce the running time of certain functions by an exponential factor over other non-strict evaluation strategies, such as call-by-name.
The benefits of lazy evaluation include:
- Performance increases by avoiding needless calculations, and error conditions in evaluating compound expressions
- The ability to construct potentially infinite data structures
- The ability to define control flow (structures) as abstractions instead of primitives
Lazy evaluation can lead to reduction in memory footprint, since values are created when needed. However, with lazy evaluation, it is difficult to combine with imperative features such as exception handling and input/output, because the order of operations becomes indeterminate. Lazy evaluation can introduce space leaks.
The opposite of lazy actions is eager evaluation, sometimes known as strict evaluation. Eager evaluation is commonly the default behavior used in programming languages.
Read more about Lazy Evaluation: History, Applications, Laziness in Eager Languages, Controlling Eagerness in Lazy Languages
Famous quotes containing the words lazy and/or evaluation:
“In clear weather the laziest may look across the Bay as far as Plymouth at a glance, or over the Atlantic as far as human vision reaches, merely raising his eyelids; or if he is too lazy to look after all, he can hardly help hearing the ceaseless dash and roar of the breakers. The restless ocean may at any moment cast up a whale or a wrecked vessel at your feet. All the reporters in the world, the most rapid stenographers, could not report the news it brings.”
—Henry David Thoreau (18171862)
“Good critical writing is measured by the perception and evaluation of the subject; bad critical writing by the necessity of maintaining the professional standing of the critic.”
—Raymond Chandler (18881959)