3 ms·
I agree. Using the truthiness of non-boolean values has always seemed questionable in any language (Javascript is possibly the worst offender). For many stati
by highfreq 16y ago
I agree. Using the truthiness of non-boolean values has always seemed questionable in any language (Javascript is possibly the worst offender). For many statically typed languages this is caught as a syntax error, which is nice for those of use prone to occasionally typos.
- baddox 16y agoThe boolean equivalents of non-boolean values are well-defined and fairly simple in Python, and I believe it's encouraged (or at least extremely common) to use them as such.
- eru 16y agoIn Haskell this is caught as a type error. But you can make your own version: class ExtendedBool t where toBool :: t -> Bool instance ExtendedBool Int where toBool = (0/=) instance ExtendedBool [a] where toBool = not . null if' v a b = if (toBool v) then a else b main = if' "String" (print "True") (print "False")