3 ms·
It is still crazy to me that in Python ('' or 10) == 10 # True That's like making the universe crazier one electron at a time. But yes, it's just about h
by KirinDave 14y ago
It is still crazy to me that in Python
('' or 10) == 10 # True
That's like making the universe crazier one electron at a time.
But yes, it's just about having the right abstractions. What's nice about the Haskell solution is that the right abstractions make the code much nicer (to my eye).
- benhoyt 14y agoI honestly don't understand why that's crazy. Empty string evaluates as falsey, so the "or" picks the 10, which is obviously equal to 10. Or am I missing something?
- deleted 14y ago[deleted]
- KirinDave 14y agoIt just seems like a bad choice. The empty string being falsey is... very arbitrary to me. It seems like it's strictly a perl legacy thing that should be (but cannot be) reconsidered. About as far as I am willing to go is nil punning.
- thecoffman 14y agoFWIW - it has been reconsidered in Ruby - all values are truthy except nil and false.
- pdonis 14y ago> The empty string being falsey is... very arbitrary to me. It's extremely useful in a lot of contexts. The basic logic is that an empty string is an empty container, and empty containers are false, so you can test for them more easily.