1. 20

  2. 10

    A good effort, but I don’t find many of these to be counterintuitive the way the popular JavaScript one is. Could just be my familiarity with Python, though.

    1. 2

      Well, the False ** False == True stuff did surprise me a bit, because I didn’t know that arithmetic functions worked on bools, and the Mixing numerical types part, but other than that it’s pretty obvious behaviors.

      1. 3

        True and False mean 1 and 0, respectively. They were added to the language relatively late, after C-style integers-as-booleans had been established and was conventional. And by “mean”, I mean “are literally aliases for”, e.g.

        >>> True * 10

        Of course, that’s still worthy of a wat. Even more wat is that this is something they didn’t fix while breaking things for Python 3.

        1. 10

          They aren’t literally aliases, no. The bools are different objects with different behavior from their similar integers; for example, they convert to strings differently:

          >>> (str(True), str(1))
          ('True', '1')

          They just convert to those integers for arithmetic.

          1. 2

            It’s true that bools are not literally aliases of int 1 and 0, but it’s very close, and they don’t convert to them. They sort of literally are them.

            >>> True == 1 and True != 2  # True really is just "1"
            >>> ['a', 'b', 'c'][True]  # just 1..
            >>> True is 1  # but still short of an alias
            >>> True is True and 1 is 1  # python ints and bools are singletons
            >>> True.numerator  # wat
            >>> isinstance(True, bool)  # of course, but
            >>> isinstance(True, int)  # AHA!
            1. 4

              Yes, but that’s not literally are them. :)

              Also, Python ints aren’t singletons; it’s just that some of them are cached:

              >>> 10000 + 10000 is 20000
      2. 2

        @journeysquid, a lot of them I could see being crazy looking if you were new to programming. After doing this for several years, though, most of these seem pretty logical to me.

      3. 3
        '2' *  3

        It makes sense and it’s symmetrical. Much better than what many languages do.

        False ** False

        What else would you expect it to do?

        + 1.0

        This is simply due to floating point imprecision. I find the alternative behaviour more confusing:

        scala> 9007199254740992.0 == 9007199254740993L
        res6: Boolean = true

        I would like a language that didn’t expose floating-point by default, but that’s probably too much to ask.

        False == False in [False]

        What did you expect that to do? It’s not very readable, but I don’t think it’s a wat.

        1 ** -1

        It’s a dynamic language, it’s supposed to be able to do that kind of thing.


        Obviously correct behaviour.

        Every language has some wats. But I think you can legitimately compare the frequency, and I think Python on the whole does quite well.

        1. 1

          What is going on in the extend example?