Caveats and boundaries: It is typically clear whether something can return a nil or accepts a nil value one versus when it doesn't. A good example would be string methods and other Java interop, where you will make sure you don't pass in a nil value, you are crossing language boundaries here so to speak. Another boundary of nil usage would be sequences, which will not evaluate to falsy, even if empty, so you explicitly would call seq or empty? on them.
The bottom line is that you are very aware of nil values and their falsiness in Clojure and that you program with them rather than against them.
Yup. It took a decade of ES updates to overcome these issues with Javascript. The falsy zero in JS has probably created more bugs in aggregate than any other language feature in history.
"Values are falsey if they are `nil` or `false`, otherwise they are truthy".
It's hard for me to map this rule to 'disaster', either in principle or in practice. It means that `if number then` does what you expect, if you expect that maybe number exists, maybe it doesn't.
It’s a bit optimistic that we’d ever have most languages working under the same rules though, no matter how sane it is and how dubious the value of falseyness (and the terseness you can get from it) is.
What's the absolute minimum level of mental imposition on an if statement? I'd say it's "this must take a boolean", but that implies compile-time types, and I'm not here to litigate the mere existence of dynamic languages today.
I would argue that the rule I sketched above is both the clearest and simplest rule which is compatible with a dynamic language. It imposes the least amount of mental burden in understanding or writing code.
if user = db.query(id)
user.update(...)
end
and user = db.query(id) || raise "UserNotFound" user = db.query(id) || raise("UserNotFound")
Or use the `or` keyword: user = db.query(id) or raise "UserNotFound"Instead of changing the boolean rules, they should definitely address the different precedence rules for boolean operators : )