by hellofunk · 8y ago · 0 comments
I use an explicit value to represent the absence of something specific like :id-unknown which is much more useful and safer than just throwing nil in there when a project scales.
If something is nil in Clojure, you have to ask why is it nil? The answer is not always simple. It could be a bug, it could be legit missing data, a number of things.
A simple typo in Clojure can give you nil. You don’t want to interpret that the wrong way.
This (anti-)pattern has a Wikipedia page, complete with Criticism section.
https://en.wikipedia.org/w/index.php?title=Null_object_patte...
Incidentally, Objective-C does something like this out-of-the-box. Unlike Java, where invoking a method on null causes an exception to be thrown, or C++, where you just get good old undefined behaviour, Objective-C 'defaults' to doing nothing. This is described in the Wikipedia article. Strikes me as a very bad idea.
[EDIT: Emphasis]