Re:Python Idioms in Rust
by davidcuddeback on Friday March 30, 2018 @03:27PM
(#16719068)
I think people take the "one way to do it" tenet a little too seriously. It comes from PEP20 [1], which to me seems to have a more jestful than dogmatic tone:
> There should be one-- and preferably only one --obvious way to do it.
> Although that way may not be obvious at first unless you're Dutch.
If I remember my history correctly, this was poking fun as Perl's "TIMTOWTDI" [2].
It also says one obvious way to do it. It doesn't preclude there being more than one way.
[1] https://www.python.org/dev/peps/pep-0020/
[2] https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to...
In 2004, "There should be only one way to do it" was a more realistic goal. 2004 puts us at Python 2.4 or so, but I think that's just when it got formalized into a PEP, it was around for a while before then. If we step back two years to 2002, we get to Python 2.1. We are now pre-generators, pre-with statement, pre-itertools, pre-decorators, and a lot of other things (useful itertools, etc.). There more often was only one sensible way to do a thing. Python evolved, but PEP20 didn't.
Re:Python Idioms in Rust
by davidcuddeback on Friday March 30, 2018 @03:59PM
(#16719334)
> 2004 puts us at Python 2.4 or so, but I think that's just when it got formalized into a PEP
I didn't notice the date on the PEP, but I think you're right. I remember reading it when I learned Python circa 2002.
Found this (from 1999): https://mail.python.org/pipermail/python-list/1999-June/0019....
The "obvious way" changes over time, as the language improves.
Re:Python Idioms in Rust
by codetrotter on Friday March 30, 2018 @03:13PM
(#16718945)
How so? Comprehensions vs loops vs recursive functions vs in some cases map/reduce/filter is the only example I can think of.
There's also strings.
'foo ' + bar
'foo {}'.format(bar)
'foo %s' % bar
f'foo {bar}'
Re:Python Idioms in Rust
by BerislavLopac on Saturday March 31, 2018 @12:15PM
(#16723858)
As well as the string templates almost nobody knows about (https://docs.python.org/3.6/library/string.html#template-str...):
Template('$foo bar').substitute(foo='foo')
Despite being a core tenet of the language, Python is _really, really_ bad at following that rule. I agree with everything else you're saying, though. Those are still Python idioms even if they originated elsewhere.