Recently I've heard definition to both of them and for me they sound identical. Is a thunk the same thing as Lazy load? If not what is the difference between those two definitions?
1 Answers
Using the following definitions:
Lazy Loading
Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed.
Thunk
A thunk is an unevaluated expression, often represented as an object on the heap with bound variables and a code pointer (a closure). Lazy evaluation replaces thunks by more evaluated forms (pure values for simple types but otherwise an evaluated outer structure, and possibly unevaluated inner contents, i.e., weak head normal form). That replacement is done destructively, i.e., a side-effect of evaluation.
You might say that "lazy loading" is a means of deferring evaluation in an object oriented language until the first time an object is demanded. When the value is required, the entire object is evaluated.
A thunk is similar in that it is a means of deferring evaluation of any expression in a functional programming language. When demanded, the thunk is replaced with its evaluated contents, which may be another thunk. In languages like Haskell, all values are (notionally) represented by thunks, making every evaluation step potentially lazy.
They are broadly similar mechanisms for achieving the same end goal: non-strict evaluation.

- 137,316
- 36
- 365
- 468