I am a horse in the land of booleans
iloveponies.github.io
I am a horse in the land of booleans
1–10 of 89 posts
Re: I am a horse in the land of booleans
#2Re: I am a horse in the land of booleans
#3Re: I am a horse in the land of booleans
#4I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
(That JS coerces the empty string to false is also bad.)
Re: I am a horse in the land of booleans
#5I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
This can get increasingly hard to reason about the more datatypes you add which interpret 0-ish values as falsey -- as there's always the temptation to do, for 'consistency' with integer truthiness, e.g. https://lwn.net/Articles/590299/ about the python behaviour of dates being falsey in the first second after midnight.
If `null` and `false` are the only falsey values (ala clojure, ruby, elixir etc), that's a rule that's really easy to internalise and reason about, so you never have to worry about things like whether your data type might be falsey in the first second after midnight (and also `if(values)` is actually a correct idiom).
Re: I am a horse in the land of booleans
#6I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
Instead of
if x = 5 and y = 7 then goto 10
use if (x = 5) * (y = 7) then goto 10
Good to know when you're 11 years old typing in some program from a magazine meant for another computer that had AND and OR.Re: I am a horse in the land of booleans
#7I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
0 and [] are real and meaningful values that have different meanings than nil/null (in what I assume you're referring to as Python) or (in JavaScript) undefined. They should be treated as such. (That JS coerces the empty string to false is also bad.)
Personally I'd prefer that not even null/undefined coerced to false, or could otherwise be used in a boolean comparison, as for me they still signify different meanings and even in type-safe languages can lead to subtle bugs. I really dislike coercion having principally worked with JavaScript/TypeScript.
Re: I am a horse in the land of booleans
#8I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
In languages with more elaborate type systems, you usually have the pointer and number representation separated.
0 has no special meaning in regards to boolean logic but it has the special meaning of the identity/zero element in an additive group. Likewise, it makes sense to have "[1] + [] => [1]" in your programming language.
But making zero elements evaluate to falsy is problematic. "" would be falsy as well then.
Re: I am a horse in the land of booleans
#9I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
In many Lisps, nil is the empty list literal, but interestingly not in Clojure, where it just maps to JVM null, and vectors are the most commonly used data type anyway. However, it is idiomatic for APIs to accept (but not return!) nil as if it were an empty sequence or collection, unlike in most non-Lisp languages.
Re: I am a horse in the land of booleans
#10I’m used to 0 and [] being falsy. Upsides and downsides to Clojure’s choice here?
0 being falsy makes no sense outside of the C family of programming languages. But there 0 is overloaded both as a number and pointer (it's a bit more complicated though, as the value of the null pointer doesn't need to be zero but assigning 0 to a pointer will assign the null pointer). In languages with more elaborate type systems, you usually have the pointer and number representation separated. 0 has no special me…
In Python 0, [], and "" are all falsy. In my experience it's only been useful - why do you consider it problematic?