Live data from Hacker News

WTF Python: Exploring and understanding Python through surprising snippets

github.com

101–110 of 169 posts

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

#101

Earlier quoted context omitted.

> I've been seeing a growing anti-python sentiment lately Not speaking for the quality of the article, but on that sentiment: maybe it's just that the pro-python sentiment is eroding. I'm glad it's becoming kind of ok to criticise that language, after years of it being untouchable (at its core, not the 2 -> 3 migration). At least that's my sentiment as someone who really doesn't like it (but I'm a professional, I sti…

I've observed the weird phenomenon that any valid criticism of Python is treated as either some kind of personal attack or because you're a mad static typing ideologue.

To be honest I feel like most criticisms against any languages are bound to sooner or later be met with the response "well, this is how this language works, and if you don't like it pick another". If you criticize a weakly typed language for an issue that is solved by strong typing, you could even argue that they are correct in saying so, unless you come up with a way to solve it without types.

I suspect that the reason that it's so common to be initially suspected of being an ideologue is that there are so many out there, and they are very vocal compared to the majority that often couldn't care less. So if you don't come up with alternate solutions, maybe the tendency is to assume you're getting at the old trope they've already heard before.

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

#102
post #21
post #5

all these cool new features! what's the thing they always say about python? "there's more than one way to do it"?

That's a Perl slogan but I suspect you already knew that

Python was always a second-rate imitation of Perl. Camel > Python.

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

#103

My biggest issue with Python that is not related to syntax is that it isolates you from the Unix machine in a bad way. I get that they try to support Windows with the same abstractions, but they are all leaky and subtly broken (like shutil). If you use Python too much, you lose the understanding of Unix. Other languages aren't like that, for example Perl and Go. Whenever I stop using Python for 2 weeks and focus on C…

There's always Ruby - best bits of Perl, Lisp and Smalltalk whilst retaining UNIX heritage.

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

#104
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…

> 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?

Yes, it is in fact extremely surprising that an expression does something different based on surrounding context. It would be as if expr had one meaning but it you called f(expr) it had another. Saying that you're using it unexpectedly doesn't really address the issue of language design.

It reminds me of Matlab's idea (a long time ago) that f(i) is either a function call or an array access at index i, but you will not know for sure until you've evaluated f, so expressions like f(i)(j) end up being just weird. There is a certain amount of logic that you are fully justified in expecting from a language.

> It's not what that operator is for.

If your idea is that an operator is free to do whatever, once it's outside its predicted situation, then I can see how that's technically correct based on the language spec, but it just seems like a very weird way to just a language design.

I think if you think that some of those examples have no legitimate uses at all you'd then have no problem saying that they should be syntax errors but are accepted anyway, that it's just a bug in the parser, that it accepts too much.

I also do not see how this is anti-python, I think you are being unfair to the author.

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

#105

Tips on learning python as a seasoned dev? I will start a new job where everything is done in Python in a few weeks. Learning the syntax of the language is easy, but what about "everything else" using a language entails? Like how is stuff written in practice (pythonic / idiomatic), build tools, libs everyone use, workflow, etc

I'm not a python developer by trade, but here are some of the resources I have found helpful. The links below are in the order I would read them if I was starting again.

Hitchhiker's Guide to Python - https://docs.python-guide.org/

* Setting up virtual environments

* Structuring projects

* Code style (PEP8)

* Popular libraries for various use cases (i.e. Django/Flask for web applications)

setup.py (for humans) - https://github.com/navdeep-G/setup.py

* Instructs on how to write a setup.py file for distributing python packages

* Contains links to other resources to learn more about setup.py

Python 3 in One Picture - http://coodict.github.io/python3-in-one-pic/

* I sometimes forget syntax when switching between different languages :)

A Guide to Python's Magic Methods - https://rszalski.github.io/magicmethods/

* The special methods typically used with object oriented python that start and end with two underscores "__"

Awesome Python - https://github.com/vinta/awesome-python

* In their own words "A curated list of awesome Python frameworks, libraries, software and resources."

* Whenever I start on a new language or skill, I always check if there is an "awesome" list available

Hope you find these as useful as I have!

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

#106
post #47

Earlier quoted context omitted.

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…

If I understand correctly, I think the problem with your second example is that you should avoid checking for `True` with something like `if isFile` but instead `if isFile is True`. That would solve this specific problem (and is also slightly more efficient because no implicit boolean conversion is performed).

You can do that, but loose checking for truthiness is pretty pythonic. It's weird to put "true" in there if you think you're checking a boolean property. If you know you're not, then you realize you need to call the function and then you can remove the "is".

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

#107
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 Not speaking for the quality of the article, but on that sentiment: maybe it's just that the pro-python sentiment is eroding. I'm glad it's becoming kind of ok to criticise that language, after years of it being untouchable (at its core, not the 2 -> 3 migration). At least that's my sentiment as someone who really doesn't like it (but I'm a professional, I sti…

You lost me at: “I prefer JS (modern) to Python”. Just... how?

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

#108
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…

Only two kinds of languages.

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

#109

Tips on learning python as a seasoned dev? I will start a new job where everything is done in Python in a few weeks. Learning the syntax of the language is easy, but what about "everything else" using a language entails? Like how is stuff written in practice (pythonic / idiomatic), build tools, libs everyone use, workflow, etc

I'm not a python developer by trade, but here are some of the resources I have found helpful. The links below are in the order I would read them if I was starting again. Hitchhiker's Guide to Python - https://docs.python-guide.org/ * Setting up virtual environments * Structuring projects * Code style (PEP8) * Popular libraries for various use cases (i.e. Django/Flask for web applications) setup.py (for humans) - http…

Will take a look, thanks!

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

#110
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 (…

Whatever language you're using, someone hates. Just be aware of that. There is no perfect language that fits every situation and there is no perfect community.

Know your needs and which language fits your needs.

Post reply on HN