Java Glossary : lazy evaluation

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : L words : lazy evaluation.

lazy evaluation
In computing, laziness is a virtue. The more ways you can think of to have the computer avoid doing work, the faster your programs will run.

It can often be optimal in computing to procrastinate computation to the last possible microsecond. If you are lucky, the computer never needs to do the work.

One common example of procrastination is to use a singleton object instead of static fields. You don't create the object until you actually need it. Just before every use, you must execute code roughly like this:

if ( singleton == null )
   {
   singleton = new Something();
   // further initialisation code ...
   }

Two other procrastination examples:

The && operator in Java avoids evaluation the right hand operand if the left hand operand is false. This is sometimes called lazy evaluation, short circuit evaluation or McCarthy evaluation. (John McCarthy was the creator of Lisp and is sometimes known as the father of artificial intelligence.)

When a function computes a value and caches the result, to produce it quickly in future without recomputing in case someone asks for the same inputs again, that is also sometimes referred to as lazy evaluation.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 1023.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/lazy.html J:\mindprod\jgloss\lazy.html