Introducing lazy evaluation and proxy objects
First and foremost, the techniques used in this chapter are used to hide optimizations in a library from the user of that library. This is useful because exposing every single optimization technique as a separate function requires a lot of attention and education from the user of the library. It also bloats the code base with a multitude of specific functions, making it hard to read and understand. By using proxy objects, we can achieve optimizations under the hood; the resultant code is both optimized and readable.
Lazy versus eager evaluation
Lazy evaluation is a technique used to postpone an operation until its result is really needed. The opposite, where operations are performed right away, is called eager evaluation. In some situations, eager evaluation is undesirable as we might end up constructing a value that is never used.
To demonstrate the difference between eager and lazy evaluation, let's assume we are...