3 ms·
> Python's community is one of the greatest and worst parts of the language. If you come from a Ruby background, and you are now doing Python, you may find you
by z9znz 4y ago
> Python's community is one of the greatest and worst parts of the language.
If you come from a Ruby background, and you are now doing Python, you may find yourself on Stackoverflow looking up how to do X idomatically in Python (something you did all the time in Ruby). Or you may ask colleagues who know Python but do not know Ruby.
A common answer from the Pythonista community is, "Why would you ever want to do that?" (or Why would you need that?)
Ternary operators? Who needs that. Ok sure, here, but let's make it awkward. Where did Python get the model to do "x = 1 if y else 2"? But ironically, unlike Ruby where you can say "x = 1 if y", in Python you cannot do that. Oh, but you cannot say "x = 1 if y else return". That's not allowed.
Python has finally, as of 3.10, added a switch statement. This is something that many other languages have had for ages. You should see the contortions people have gone to to approximate a switch statement in Python... https://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python https://stackoverflow.com/questions/60208/replacements-for-s...
The Python community may have some good, helpful, and friendly people; but most programming communities have that. That is not a plus for any language, because it should be a given.
- nemothekid 4y agoI'm not a Pythonista by any means, but these complaints are banal. Ternary operators? Plenty of new popular languages don't have a ternery operator (Go, Rust, Elixir, Kotlin, Nim). My list of python gripes are long, but language constructs are not on the list.
- z9znz 4y agoThe point is about inconsistency. You can say "x = 1 if expr else 2", but you cannot say "x = 1 if expr". You do a two line if expr: x = 1 You cannot say "x = 1 if expr else return". [1] is a list with one item, 1. {1} is a set with one item, 1. (1) is a number, 1, with pointless parenthesis. Perhaps you mean (1,), a tuple containing only one value. Or how about mutable default values in function paramters? That makes a lot of sense... I don't need to keep offering examples. You can search the internet and find many places where people list the warts, inconsistencies, and misfeatures of Python.
- pbourke 4y agoThese are pointless nitpicks. Every language has things like this. In 4 years of using Python in anger I’ve never written a line of code that could be improved by the features you list.
- z9znz 4y ago> These are pointless nitpicks. Every language has things like this. In 4 years of using Python in anger I’ve never written a line of code that could be improved by the features you list. This is exactly the kind of response one often hears from the Python community. Translated it means, "I'm ok with it this way, so who cares if it could be better?"
- nickles 4y ago> You can say "x = 1 if expr else 2", but you cannot say "x = 1 if expr". You do a two line This one liner works: if expr: x = 1 > Or how about mutable default values in function paramters? That makes a lot of sense... This can be helpful under certain circumstances (e.g. memoization) [1]. The linked article also points out that it can be useful for rebinding global names in optimized code. [0] https://stackoverflow.com/a/1145781 https://stackoverflow.com/a/1145781 [1] https://web.archive.org/web/20200221224620id_/http://effbot.org/zone/default-values.htm https://web.archive.org/web/20200221224620id_/http://effbot....
- z9znz 4y ago> if expr: x = 1 But PEP8 and now the all-too-popular Black formatter disallow this. I think it's fine. The momoization/optimization point is exactly the opposite of what should be a default use case for a beginner friendly language. And I highly doubt this mutable default design was intentional for these purposes. They are footguns.