5. Epilog

It's just a matter of checking to see if a value is null, but humans can't do it perfectly. To overcome a lapse of null checks, we have seen various improvements such as null object patterns, option types, nullable types, and static analysis of the compilers. But can you say with confidence that the cost of introducing those complexities is worth the effect?

The book Software Tools [1] describes error handling as follows:

Error checking interferes with readability, no question about it, but it is necessary. With the best of languages, error checking obscures the main flow of events because the checks themselves impose a structure on the code which is different from that which expresses the basic job to be done. Programs written from the start with well thought out error checks, however, prove to be more reliable and live longer than those where the error checking is pasted on as an afterthought.

If you replace error checking with null checking, the situation doesn't seem to have changed much over the past 40 years. Of course, many languages are now able to separate the structure of exception handling from that of normal handling with mechanisms like throwing and catching exceptions. However, nothing has changed in terms of checking the return value in normal handling and then performing something depending on the kind of the value.

There is also a significant difference in usability, in terms of the null safety of programming languages, between one that has a trick added from the middle version of the language and one that is endowed by nature with it. The null safety which is inborn is quite different from acquired. To appropriate the expression in [1], “Programming languages designed from the start with well-thought-out null safety prove to be more reliable and live longer than those where the null safety is pasted on as an afterthought.”

Finally, the debate about null safety seems like the old goto. It will get better anyway with removing goto. Or a ghost of goto called labeled break appears despite having buried goto. Even if you conceal goto, the concept never disappears. It is the same for null. The situation where you have at most one value continues to exist with or without null.

References

  1. Brian W. Kernighan, P. J. Plauger, P. L. Plauger. Software Tools, Addison-Wesley, 1976.