lazy evaluation
also: delayed evaluation, non-strict evaluation
A computation strategy where values are calculated only when actually needed, rather than in advance. Common in functional programming and shell scripting to improve performance and handle infinite sequences.
Lazy evaluation defers the execution of code until its result is required. This contrasts with eager evaluation, where expressions are computed immediately. In Linux shells and scripting, this is often seen with short-circuit operators and shell built-ins that don't evaluate all arguments upfront.
For example, in bash the logical AND operator && only evaluates the right side if the left side succeeds: test -f file.txt && cat file.txt will only read the file if it exists. If the test fails, cat is never executed.
Lazy evaluation is valuable for efficiency—avoiding unnecessary computation and I/O—and for correctness when dealing with conditional logic. Some languages like Haskell make it the default evaluation model, while in bash it's available selectively through operators like &&, ||, and conditional constructs.