News for hackers. Stuff that matters.
Re:The Zen of Python by Example by highfreq on Thursday February 10, 2011 @05:19PM (#2204084)
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.
Re:The Zen of Python by Example by baddox on Thursday February 10, 2011 @05:56PM (#2204228)
The 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.
Re:The Zen of Python by Example by eru on Friday February 11, 2011 @06:40AM (#2205970)
In 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")