|
|
|
|
|
by jrockway
5233 days ago
|
|
I've never actually noticed "one obvious way". There are a couple ways to do almost everything in Python; loops or map, Twisted or threads, unittest2 or nose, and so on. I like Python, but human nature pushes everything towards "there are many ways to do it", and humans have influenced the direction of Python. I prefer Perl's approach of embracing more than one way to do things. I don't really want there to be 8 ways to do one thing, but it's just a more realistic outlook. You go into Perl knowing that you are going to have to try a bunch of different things to see what fits your mental model, instead of being told what to do. (I used Python at a Bank where they wrote their own style guide, completely different from the standard Python style guide. WTF? Humans have a way of ruining everything.) Ironically, many things in Perl have converged into "One Obvious Way"; PSGI/Plack for web frameworks, Test::Builder for unit tests, and so on. |
|
There are always more than 1 ways to do something, but Python tries to be directive towards the recommended way for the core.
For the given snippet, using reduce for loops is frowned upon; nothing is stopping you from doing it, but the general opinion is you shouldn't do it. I think that counts as there being an obvious way.
As far as maps and list comprehension go, that isn't clear-cut but people incline towards comprehensions.<nitpick> Twisted(reactors) and threads implement two different things which serve different purposes, and unittest2 is a lib while nose is a test runner. </nitpick>
That said, there is always going to be many ways to do something, but it helps if the core tries to stick with a uniform way to do things.