Another question

Thomas Wouters thomas at xs4all.net
Tue Apr 18 17:49:32 EDT 2000


On Tue, Apr 18, 2000 at 02:01:32PM -0600, Jeff Massung wrote:

> 2. There are many different ways to do something (ala Perl) - which has
> drawbacks and advantages.

You've failed to spot the obvious difference between the many different ways
of Python and the many different ways of, eg., Perl, though ;)

In Python, everything is based off a few very simple concepts. For instance,
the namespace tricks you saw in this thread all boiled down to 2 simple
things:

- Assignment does not copy an object, it only binds a local (or, when you
use the 'global' keyword on the name first, a global) name to that object.

- Everything is an object, and you can any object anywhere.

In comparison, Perl idioms often deal with special cases (or so it seems
from my point of view) -- usually (but absolutely no way near always)
confusing perl constructs can be boiled down to some form of logical rule,
but the overall quantity of 'logical rules' is immense, compared to Python.

(I could post some perlish examples if necessary, but I'm sure noone here
wants to see them ;)

Of course not all Python code can be boiled down to these two things (they
aren't really 'rules', by the way, merely descriptions of the Python view of
the world) but understanding these subtle differences can really make you
grok Python ;) Tim Peters once wrote down the Python Philosophy (or zen):

"""
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
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.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

dict-is-short-for-dictator-cuz-gui-was-already-in-use-ly y'rs  - tim
"""

And I must say, thinking about the entries I didn't understand right away
brought me lots closer to the Truth, and rethinking those I thought I'd
figured out right away even more ;)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list