3 ms·
> They don’t violate the spirit of the language. They are optional. That in itself violates the spirit of the language, IMO. “There should be one obvious way t
by pansa2 1y ago
> They don’t violate the spirit of the language. They are optional.
That in itself violates the spirit of the language, IMO. “There should be one obvious way to do it”.
- graynk 1y agothe whole language violates this principle tbh, so it's very in spirit
- tdeck 1y agoYeah that ship sailed some time before they added a third way to do templated string interpolation.
- kketch 1y agoWell, precisely: - There is one obvious way to provide type hints for your code, it’s to use the typing module provided by the language which also provides syntax support for it. - You don’t have to use it because not all code has to be typed - You can use formatted strings, but you don’t have to - You can use comprehensions but you don’t have to - You can use async io, but you don’t have to. But it’s the one obvious way to do it in python The obvious way to annotate a generic function isn’t with a giant Union, it’s with duck typing using a Protocol + TypeVar. Once you known that, the obvious way is… pretty obvious. The obvious way not be bothered with type hints because you don’t like them is not to use them! Python is full of optional stuff, dataclasses, named tuples, meta programming, multiple ancestor inheritance. You dont have to use these features, but there are only one way to use them
- zx8080 1y ago> but there are only one way to use them Optional nature of those features conflicts with this statement. As optionality means two ways already.
- preciousoo 1y agoclasses are optional in python, does that violate the spirit?
- TZubiri 1y agoHow so? There is one way to do it. If you want typing, you use type hints. You wouldn't say that, say, functions are unpythonic because you can either use functions or not use them, therefore there's two ways to do things, would you?
- bityard 1y ago"There should only be one way to do it" has not really been a thing in Python for at least the last decade or longer. It was originally meant as a counterpoint to Perl's "there's more than one way to do it," to show that the Python developers put a priority on quality and depth of features rather than quantity. But times change and these days, Python is a much larger language with a bigger community, and there is a lot more cross-pollination between languages as basic philosophical differences between the most popular languages steadily erode until they all do pretty much the same things, just with different syntax.
- dragonwriter 1y ago> "There should only be one way to do it" has not really been a thing in Python for at least the last decade or longer. It never was a thing in Python, it is a misquote of the Zen of Python that apparently became popular as a reaction against the TMTOWTDI motto of the Perl community.
- bityard 1y agoNot misquoted, paraphrased. I didn't feel like bothering to check the output of "import this" before posting.
- lexicality 1y agoon that note, which is better, using `map()` or a generator expression?
- xzel 1y agoAnd Python failed at that decades ago. People push terribly complicated, unreadable code under the guise of Pythonic. I disagree with using Pythonic as reasoning for anything.
- xzel 1y agoAnd Python failed at that decades ago. People push terribly complicated, unreadable code under the guise of Pythonic. I disagree with using Pythonic as reasoning for anything.
- dragonwriter 1y agoThis is a popular misquote from the Zen of Python. The actual quote is “There should be one—and preferably only one—obvious way to do it.” The misquote shifts the emphasis to uniqueness rather than having an obvious way to accomplish goals, and is probably a result of people disliking the “There is more than one way to do it” adage of Perl (and embraced by the Ruby community) looking to the Zen to find a banner for their opposing camp.