python idioms : some are confusing

Chris Angelico rosuav at gmail.com
Fri Sep 21 02:07:13 EDT 2012


I'm responding to the OP here, not to Alex, but I'm quoting his text
to expand on it. :)

On Fri, Sep 21, 2012 at 3:52 PM, alex23 <wuwei23 at gmail.com> wrote:
> On Sep 21, 3:34 pm, Vineet <vineet.deod... at gmail.com> wrote:
>> Amongst the python idioms, how the below-mentioned make sense?
>> ## There should be one-- and preferably only one --obvious way to do it.
>> --- In programming, there can be a number of ways, equally efficient, to do certain  thing.
>
> This isn't talking about your Python code as much as about Python
> itself.

The "it" in the zen there refers to some programming task. For
instance, there's only one obvious way to increment an integer:

spam += 1

Python's philosophy is to have just that, and to not trouble itself
with "spam++" and "++spam" and the distinction between them. As a C
programmer, I'm quite accustomed to them, and know what they mean, but
not everyone does. And don't get me started on "&&" vs "and" in PHP...
Python is a simpler and cleaner language for not having superfluous
operators.

>> ## Although never is often better than *right* now.
>> --- How come "never" is better that "right now" ?
>
> It's better to not add a language feature than it is to add it poorly,
> especially when you endeavour to provide backwards compatibility as
> much as possible within major versions.

The compatibility issue is the thing here. It's better to get
something good now rather than dither for another fifty years, because
the longer you dally, the more code will be written using third party
libraries. But it's better to not put it into the standard library at
all than to put in a messy API that now can't be changed because
code's using it.

The Zen of Python is a whole lot of tradeoffs and ideas. Several of
them balance each other directly. Some, while not contradicted in the
Zen itself, are still violated at times in the language and/or stdlib.
They're principles, not laws, and need to be read with the
understanding that people who write code are intelligent, thinking
beings (though a quick look at TheDailyWTF.com proves that this is not
universal).

ChrisA



More information about the Python-list mailing list