Null: What Is It Good For?
This chapter has taken a largely anti-null stance. We view this stance to be a noble one, but in the wild world of software engineering, representing state using null is common.
Why? Null is often used in Java and languages of its ilk as an initial value for variables. For example, think of a variable declared to hold a person’s name. There are common first names for human beings, but no name can be considered a default. Null is often used as an initial value for variables that have no natural default value. In fact, in many languages, you can define a variable without assigning it a value, and its value will default to null.
This mentality of defaulting to null can lead to null pointer exceptions, which ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access