Why and how "there is only one way to do something"?

Terry Hancock hancock at anansispaceworks.com
Thu Dec 15 09:05:30 EST 2005


On 15 Dec 2005 05:08:02 -0800
bonono at gmail.com wrote:
> I would say that if "only one way to do it" is the intend,
> make it into the language and any other way is simply
> error. Say if ternary operator is not the "preferred way",
> don't have it in the language. If someone find a way to
> work around it, change that part of the language to break
> their code.

But that is precisely what it does mean -- Python's language
design tries to be "reasonably minimal": there's usually one
fairly easy way to do a task. Unintentionally, there may
well be a half-dozen really hard ways to do it. The point of
telling this to the potential coder is to suggest that "if
it's hard, you're probably doing it the wrong way" and nudge
them into looking at how the language designers have
intended those problems to be solved.

But of course, this is simply a reaction to the Perl motto:
Having a half-dozen more or less equally difficult, equally
documented methods, with no expressed preference, means that
you will find all half-dozen in the wild, which means in
turn that reading and understanding code is six-times harder
to do. Since readability is the primary use of source code,
this translates to the language being pretty close
to six-times harder to use overall.

The problem that has happened with Python is that as the
language is improved, the old "best way" gets replaced with
a new "best way" (hopefully easier).  The Python development
team's response to this problem is to specifically
deprecate the old way, and encourage users to adopt the new
way.  Generally, the old way does still work so that code
isn't needlessly broken, though there have been exceptions
(such as when the scoping rules were changed).

OTOH, no one can possibly anticipate everything you need to
do, and it is always possible that you have important
requirements for doing things a certain way. We assume that
you are mature enough to know the difference between
"breaking the rules accidentally" and "breaking the rules on
purpose".


-- 
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com




More information about the Python-list mailing list