© Jennifer M. Kohnke
Faultily faultless, icily regular, splendidly null, Dead perfection, no more.
—Lord Alfred Tennyson (1809–1892)
Consider the following code:
Employee e = DB.GetEmployee("Bob");if (e != null && e.IsTimeToPay(today)) e.Pay();
We ask the database for an
Employee object named
DB object will return
null if no such object exists. Otherwise, it will return the requested instance of
Employee. If the employee exists and is owed payment we invoke the
We’ve all written code like this before. The idiom is common because, in C-based languages, the first expression of the
&& is evaluated ...