WTFPython – Understanding Python through surprising snippets
1–10 of 199 posts
Re: WTFPython – Understanding Python through surprising snippets
#2Re: WTFPython – Understanding Python through surprising snippets
#3I remember reading this a couple years ago and it opened my eyes to things that I was oblivious to.
Re: WTFPython – Understanding Python through surprising snippets
#4In my experience Python is not very nice to work with. I do like the ecosystem for data science though, it's just amazing how much there is. Hopefully the language will grow into something better now that the dictator stepped down.
Re: WTFPython – Understanding Python through surprising snippets
#5Re: WTFPython – Understanding Python through surprising snippets
#6Re: WTFPython – Understanding Python through surprising snippets
#7If only it had curly braces instead of just indention. God, that kills me. And used unicode instead of ascii as the default. And there wasn't python 2.7 vs 3. Someone help me stop this list.
2. can't help with the whitespace, sorry; also take care handling Makefiles
Re: WTFPython – Understanding Python through surprising snippets
#8Take for instance:
>>> powers_of_x = [lambda x: x^i for i in range(10)]
>>> [f(2) for f in powers_of_x]
[512, 512, 512, 512, 512, 512, 512, 512, 512, 512]
To me this is more absurd than any of the JS “wat”s I’ve seen.
In JS:
powersOfX = Array.from({length: 10}).map((_,i) => x => x^i)
powersOfX.map(f => f(2))
Not a particular fan of the Array.from over list comprehensions in terms of syntax, but I much prefer consistency of semantics JS provides by not adding new syntax.
Here Python has special syntax for both list comprehensions and for anonymous single line functions, and they interact in a highly unexpected way.
Funny that Py doesn’t need semicolons, as I’m reminded of GJS telling me of adding special forms to languages: “beware the allure of syntactic sugar, lest you bring upon yourself the curse of the semicolon” (paraphrased of course, he said it much better). It seems Python has fallen into the trap of syntactic sugar, with the curse manifesting itself not in the form of a semicolon, but in confusing and unexpected interactions between its various special forms. Another example: the walrus operator and all its oddities listed in TFA.
Re: WTFPython – Understanding Python through surprising snippets
#9Maybe "beautifully designed" is a bit much then In my experience Python is not very nice to work with. I do like the ecosystem for data science though, it's just amazing how much there is. Hopefully the language will grow into something better now that the dictator stepped down.
Given how long it took to transition to Python 3 and how painful the transition was, I'm not sure people will have the appetite or patience for this anytime soon.