Live data from Hacker News

WTF Python: Exploring and understanding Python through surprising snippets

github.com

111–120 of 169 posts

Re: WTF Python: Exploring and understanding Python through surprising snippets

#111
post #47

Earlier quoted context omitted.

I think you forgot the link to your collection?

There are some that you can find in [0], but they are often de-contextualized (and sometimes aren't really Python's problem, because there was a trade off that had to be made, and the LOL is just frustration as a result of the bad ergonomics that it creates), those and some others will eventually go in an longer post when I finally get that set up. To give one concrete example of an LOL PYTHON consider the @property…

I am not trying to be edgy here when I say that I have viewed a lot of the "syntactic sugar" business with a great deal of skepticism. Piggybacking off of your example, upon reflection I believe that me looking askance at decorators is partially a learned fear (I escaped Perl), and partially because decorators seem a little like "bad magic," where you have cast a handy but seemingly innocuous spell only to find that it has deeper consequences later.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#112
post #12

I feel like WTFs caused by doing something deeply weird hardly counts against the language. Yes doing the walrus operator inside brackets works. Yes of course it's going to be doing weird things. Is this really surprising to anyone? It's not what that operator is for . Yes comparing strings with "is" works sometimes . It's not checking equality and it isn't supposed to. In another implementation using "is" might work…

> I've been seeing a growing anti-python sentiment lately, and most of it seems to be based on these sorts of odd perceived language defects.

I've seen the same, but to me it feels like the downslope of the hype-train that was brought on by the ML crowd. Early on there was python doing python things, and the (IMO overly smug) community was happy with that. Then the AI/ML hype train fired up and for historical #reasons python became the language of choice, and this introduced a LOT more people to the language, and it became their lingua franca.

Now, those people are having to write honest to god applications and are finding that python is Hard To Scale, both technically and code-management-y.

IMO. Reasonable people disagree.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#113
post #87
post #12

I feel like WTFs caused by doing something deeply weird hardly counts against the language. Yes doing the walrus operator inside brackets works. Yes of course it's going to be doing weird things. Is this really surprising to anyone? It's not what that operator is for . Yes comparing strings with "is" works sometimes . It's not checking equality and it isn't supposed to. In another implementation using "is" might work…

Critiquing X, or even warning people about surprises in X, is not "anti-X". Have people picked up this weird idea from fandom culture or something? This article is not saying that people should not use python. It's not criticizing the maintainers for making stupid decisions, as far as I can see. It's just saying "if you do this, you'll get a surprising result", and in the process teaching people more about how it act…

> I've written a lot of C in the subsequent 20 years or so. It has some particularly nasty traps. Acknowledging that does not make me anti-C.

depends on your cultural background I guess. Some people see literally everything that is not 100% risk-free as inherently bad.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#114
post #28

While this repo is great for education, it doesn't cover the deep problems with Python that you only discover when you try to do something "unapproved" or slightly off the happy path. Depending on the domain you are working in you may never encounter such a situation, but if you do, be prepared to lose your sanity one omnipresent design flaw at a time. Over the years I've been collecting a series of cases that are so…

That's the flip side of "There should be one— and preferably only one —obvious way to do it." Engineering is the art of trade-offs. Same problem with different requirements needs a different solution.

Enter Django.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#115
post #48

Earlier quoted context omitted.

In python, strings are mostly unique, meaning that a string can be bound on many variables, and all the variables point to the same string. This is where the 'is' operator comes in, 'is' checks for reference equality, that is, the object that is bound onto the two variables is the same. If they are not the same, 'is' fails. In other words: x = "foo" y = "foo" x == y and x is y Both strings point to the same exact mem…

Checking for reference equality (comparing pointers) is such a niche requirement it should be hidden behind stronger syntactic vinegar. The greatest mistake Java made maybe is having == for testing pointers, and .equals() function for actually comparing. Every JVM language that came after Java reverses this. Here, "is" simply is too nice. Should've named it something nobody will accidentally use.

It’s not even that. CPython happens to sue memory address as ID, but the language doesn’t require that. You could easily use something else for the object ID and get completely different behavior.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#116
post #59

To be frank I think the python community lacks self-awareness. There's this ritual you have to do when learning python: blindly accept status-quo design choices as "universally good" (but call it "pythonic"), and crap on other languages. Never admit python or the ecosystem has issues or shortcomings, and if another language has something better than yours (eg, Yarn, or Composer is way better than anything in Python (…

I can't disagree. With one exception, that being Raymond Hettinger, it's to the point of cringiness when someone says "pythonic". The last 2 years of my last job was 99% python, and the smug, "we love what we did and nothing else" attitude I think you've exactly captured.

I know this is not universal, but I've seen it online a lot, and lived it for far too long.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#117
post #59

To be frank I think the python community lacks self-awareness. There's this ritual you have to do when learning python: blindly accept status-quo design choices as "universally good" (but call it "pythonic"), and crap on other languages. Never admit python or the ecosystem has issues or shortcomings, and if another language has something better than yours (eg, Yarn, or Composer is way better than anything in Python (…

To take one of your complaints: > Why do my lines of code need to fit on a punched card invented decades before the language was invented? Keeping lines short helps keep information density high, allows you to fit more views of the code on screen without wrapping, and encourages use of intermediary variables to keep complexity per line low. This isn't a Python issue. Any decent style guide will have a maximum line le…

Line length isn't a python issue. A line length of 80, is. (Thus the punch card reference).

My stint in python made me appreciate A line length more, but 80 got to be absurd.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#118
post #79
post #59

To be frank I think the python community lacks self-awareness. There's this ritual you have to do when learning python: blindly accept status-quo design choices as "universally good" (but call it "pythonic"), and crap on other languages. Never admit python or the ecosystem has issues or shortcomings, and if another language has something better than yours (eg, Yarn, or Composer is way better than anything in Python (…

To me this sounds like a big straw man of a "the python community" that does not exist in that form. Things like the packaging system being shortcomings is widely acknowledged, I've very rarely encountered people being dogmatic about "pythonic" code, especially when it just comes to style guide. You've encountered one or two, and are extrapolating to an entire community about that.

You berate someone for limiting his post to his context and do the exact same thing yourself.

> I've very rarely encountered people being dogmatic about "pythonic" code,

Followed by...

> You've encountered one or two, and are extrapolating to an entire community about that.

I'll have to say my experience in "the community" has been far closer to his experiences than your equally small bubble.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#119
post #12

I feel like WTFs caused by doing something deeply weird hardly counts against the language. Yes doing the walrus operator inside brackets works. Yes of course it's going to be doing weird things. Is this really surprising to anyone? It's not what that operator is for . Yes comparing strings with "is" works sometimes . It's not checking equality and it isn't supposed to. In another implementation using "is" might work…

> I've been seeing a growing anti-python sentiment lately, and most of it seems to be based on these sorts of odd perceived language defects. I've seen the same, but to me it feels like the downslope of the hype-train that was brought on by the ML crowd. Early on there was python doing python things, and the (IMO overly smug) community was happy with that. Then the AI/ML hype train fired up and for historical #reason…

"Hard to scale" isn't really a coherent argument against any mainstream programming language.

It's kind of like saying that AMD processors or Microsoft Word are hard to scale - it's not entirely meaningless as a criticism but it's close to it.

Python is not a language for writing ultraperformant multi threaded code but, of course, that's not what it used for or was ever intended to do and is an entirely separate issue to scalability.

Reasonable people disagree about well defined, important matters.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#120

    >>> a := "wtf_walrus"
    File "", line 1
        a := "wtf_walrus"
          ^
    SyntaxError: invalid syntax
Why doesn't this work? Isn't the walrus operator effectively just an alternative to the assignment operator which also returns the assigned value? Why specifically make it fail in this situation?
Post reply on HN