5 ms·
> Python especially, with its "one way to do it" Despite being a core tenet of the language, Python is _really, really_ bad at following that rule. I agree wit
by spyspy 9y ago
> Python especially, with its "one way to do it"
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.
- codetrotter 9y agoHow so? Comprehensions vs loops vs recursive functions vs in some cases map/reduce/filter is the only example I can think of.
- strkek 9y agoThere's also strings. 'foo ' + bar 'foo {}'.format(bar) 'foo %s' % bar f'foo {bar}'
- BerislavLopac 9y agoAs well as the string templates almost nobody knows about (https://docs.python.org/3.6/library/string.html#template-strings https://docs.python.org/3.6/library/string.html#template-str...): Template('$foo bar').substitute(foo='foo')
- davidcuddeback 9y agoI 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/ https://www.python.org/dev/peps/pep-0020/ [2] https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to...
- jerf 9y agoIn 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.
- davidcuddeback 9y ago> 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/001951.html https://mail.python.org/pipermail/python-list/1999-June/0019....
- xapata 9y agoThe "obvious way" changes over time, as the language improves.