Wow, almost 5,000 hits and still going strong. I appreciate the feedback, which has surpassed my expectations of none. Page views down this dark alley usually hover around two or three a day, so I'm still not sure whether or not to file a bug report with TypePad (perhaps they forgot to carry the 0).
Anyway, I wanted to take some time to address some comments I've read here.
Missed the point
For those of you who missed the point of the article, let's try this one more time.
A predicate modifies a subject. Check. A predicate asserts some truth about the subject. Check. Without a subject, a predicate has nothing to modify. QED.
Or for you more manly programmers (this is just a joke, keep reading), how about a CFG:
Sentence => Subject Predicate
Subject => Shirt | NULL
Predicate => is blue
Those are your productions. Your non-terminals are bolded and your terminals are not. The language defined by that CFG yields the sentence:
"is blue."
Throw that sentence out in casual conversation.
What I thought was an obvious point went over the heads of most readers. I have to assume I did a terrible job explaining myself. So here is an equation to help:
NULL + Boolean = ambiguity
Now I cannot speak for you, but I have a hard time finding a place for ambiguity at my dinner table of logic. If we modify a null subject with a predicate, we assert some truth that carries ambiguity because the assertion carries an implication regarding the subject. In our blue shirt example we yield false when the shirt is not blue and when we do not have a shirt to modify. This is ambiguity.
Really missed the point
Quite a few comments were made regarding my desire to banish NULL from the universe. I'm not sure what post you were reading, but it surely was not mine.
I stumbled upon this noteworthy comment:
"'NULL makes things messy get rid of null'".
That comment was made as a summary of my post, and what a terrible summary it was! Shame on you.
Funny on accident
Here is my favorite comment by far:
"What happened to programmers being real men? I'm talking about doing things like allocating and freeing memory, doing pointer arithmetic and using multiply linked lists, all before a hearty breakfast of steak, vodka and cigars.
Now, coddled by managed code, generics and closures, we see febrile man-children wetting their pants about something as simple as nulls. Man up for fuck's sake."
Now that is funny! Let's pick this one apart:
- "What happened to programmers being real men?". What happened to insightful input. As a general rule of thumb, if the first sentence of a comment is an ad-hominem attack then the commenter is more than likely a real man, perhaps even one that wears Old Spice and eats deep fried bacon.
- "I'm talking about doing things like allocating and freeing memory, doing pointer arithmetic and using multiply linked lists...". Now I know this is a real man! One that throws abstraction and grammar to the wind!
- "Now, coddled by managed code, generics and closures...". Wow, just wow.
- "...wetting their pants about something as simple as nulls. Man up for fuck's sake.". Sexism aside, would you mind helping me change my pants?
Monads
I came across several comments suggesting that the venerable Maybe Monad (nullable value type) would solve this particular problem. While it does solve this particular problem, let’s not lose sight of the actual problem.
A nullable Boolean would certainly remove any ambiguity, essentially giving us the third Boolean value “I don’t know”. So now we are asserting the fact that we do not have a subject to modify, which is the actual problem. It may sound like we’re getting closer, but we’re not.
What are our choices for dealing with this new Boolean value? Well I suppose it depends on the context of the program. Perhaps it is OK and we can continue on our merry way. Imagine a customer wanting to purchase blue shirts. The customer applies some type of filter, and this filter removes non-blue shirts. A non-existent shirt is not blue, so the filter gladly ignores it. We then return all blue shirts and our customer is happy.
But now imagine our customer wants to purchase every non-blue shirt and we use the same filter. Every time our filter returns false, we sell that shirt to our customer. Uh oh. We will attempt to sell a NULL shirt to our customer, which would more than likely result in an exception somewhere down the line.
Remember, our problem is not that the Boolean type is insufficient. So why amplify it? (I’m not making a case against nullable types, I’m just making an observation).
Ignoring the problem
I was surprised to see how many “solutions” were presented which did not directly address the problem. Rather, many solutions targeted the Boolean type as not being meaningful enough.
Perhaps my sense of humor is senseless, but I find all this rather amusing. Look around at all the abstraction and complication we create to deal with such a basic issue. I’m not saying this abstraction and complication is not necessary. I just find humor in our ability to complicate.
Actual insightful commenters
Imagine how happy I was to find how many other programmers saw the problem, laughed a bit, and got involved in meaningful discussions. Thank you to those people, you’ve most definitely taught me a few things.
Would a non-issue has sparked such a debate? I would like to think not, but I am biased.
Wrapping up
I wrote "Dear NULL" in literally an hour. I stumbled upon a block of code that looked very similar to the one posted in that article, and it just made me stop and think for a moment. After thinking about it, it made me laugh a bit.
There are countless ways to deal with NULL, and each language offers new and enlightening abstractions to push the problem further away from its realization.
Monads are an option, namely the Maybe monad. Contracts could work. A change of perspective and/or changing the name of function could help. Building a JK flip-flop with some spare gates and doing some other manly shit would probably just make me wet my pants.
I merely found a block of code that made me giggle.