"null Considered Harmful"

K

Kaz Kylheku

not according to the OO people. The NullClass is a recognised design pattern.
The claim is it simplifies things!

The blog rant is about null references.

A null object with a null class (like the nil object in Common Lisp, which is
of class null) is a different beast from null references. Null references are
invalid values of their respective reference types: null reference to a String,
null reference to a Stream, etc.

This means that just because your method takes a string class doesn't mean
you're out of the woods; that argument may still be null.

In a OO language with a real nil, that wouldn't be the case: a method argument
for a string class would never receive a nil argument.

(defmethod foo ((obj null))
(write-line "null version of foo called"))

(defmethod foo ((obj string))
(write-line "string version of foo called"))

(foo nil)
null version of foo called

(foo "abc")
string version of foo called

The blog author calls for the abolishment of null references from high level
languages. Evidently, he has never used one.
 
K

Kaz Kylheku

It's a case of coding riund deficiencies in a language.
If the language doesn't have a concept of "null", you can create it by adding
an "isnull" flag to every object, then checking it in every member function.
It's tedious, but it works.

Your program is no longer object-oriented, since you're cehcking for type
everywhere. "Is the object of my type? Or is it of null type, which is effectively
a different class (though not recognized as such by this piece of shit language)?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,075
Messages
2,570,545
Members
47,197
Latest member
NDTShavonn

Latest Threads

Top