Why Even Have the NULL Value at all?
Years ago, I read C. J. Date’s essay about NULL in relational databases. If you didn’t know Date, he was, perhaps still is, one of the major figures in relational database circle. And I learned tremendous amount of stuff from his writing, much more than what I got from university. How was that so? Bad university teaching? Well, for one thing, when I was studying databases in university, we did not have proper SQL yet. Yup, I am that old. So, learning SQL on my own when I was working in a bank, I relied a lot on his writings to learn stuff about SQL. I had no issues with relational calculus or algebra. We did have those already when I was in school. Just that we had to “simulate” QUEL on paper, as we did not have any relational databases at all. We did have network and hierarchical databases, but those were all too expensive for the course to allow us to practice on them. That was the era when departments of the same university paid each other “funny money” so that they could have proper accounting in terms their funding. So, we did not have access to the IBM mainframes, only minicomputers from DEC, CDC, etc. Anyhow.
One of Date’s essays talked about the three-value logic in SQL, true, false, and null. I don’t remember the details any more. I am sure I can still find the essay, among the books all over my place. I remember he did not quite sure whether he should like it or not.
I don’t know about you, but the null value is very useful for me for my database programming. It is a bit messy, obviously, as it can mean “missing value”, “no value”, “no value yet”, etc. So it is quite hard to tell what the semantics of a null value for a column in a table. And worse, maybe the database designer has decided to use null to mean more than one thing. Also, once you have more than one column having the null value, you have to be careful to check if the columns are related. Again, many database designers don’t move these columns out to be their own tables, normal forms be damned. If they know what normal forms are in the first place.
I use all three meanings in my database. I wish we had three different nulls, obviously. Woah woah woah, did I just say I wish we had more than one kind of null values? Isn’t null bad? I mean, it is a billion-dollar mistake, right?
Not really. The thing is, if you want to model the real world as closely as possible, we do have null values all over the place. The fact that the traditional and convention wisdom says that null values are bad does not make it so. Yes, maybe our programming languages and tools don’t handle null values well, but that is not a good reason to throw the baby out with the bath water.
Do we have programming languages with no such concept at all? Of course. FORTRAN 77 did not have it. I don’t know whether it has it now or not; I have not programmed in FORTRAN like for decades now. But then FORTRAN 77 did not have recursion either. Is recursion bad? It could be, I mean, it has one more exception to worry about, right? The stack overflow exception? Is that as bad as a null pointer exception? I don’t know. Maybe?