Live data from Hacker News

WTFPython – Understanding Python through surprising snippets

github.com

1–10 of 199 posts

Re: WTFPython – Understanding Python through surprising snippets

#4
Maybe "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.

Re: WTFPython – Understanding Python through surprising snippets

#7

If 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.

1. forget python 2.7 exists

2. can't help with the whitespace, sorry; also take care handling Makefiles

Re: WTFPython – Understanding Python through surprising snippets

#8
My biggest complaint about Python is that it somehow doesn’t get flak for having the same (if not worse) scoping as JS, which gets endless hate for its function-scoped variables. (So much so that block scoped variables are the new normal in JS, but not in Py!)

Take 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

#9
post #4

Maybe "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.

Fixings a lot of the WTFs requires breaking backwards compatibility.

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.

Post reply on HN