Why and how "there is only one way to do something"?
Steve Holden
steve at holdenweb.com
Thu Dec 15 07:32:26 EST 2005
Tolga wrote:
> As far as I know, Perl is known as "there are many ways to do
> something" and Python is known as "there is only one way". Could you
> please explain this? How is this possible and is it *really* a good
> concept?
>
Perl's credo is actually "There's more than one way to do it", often
abbreviated to TMTOWTDI.
(Part of) Python's credo (which you can read in context by typing
import this
at an interactive command prompt) is "There should be one (and
preferably only one) way to do it".
Clearly as Python is improved (well, develops, anyway :-) new ways to
perform old tasks will become possible. So the obvious way to iterate
over the lines of a text file *used* to be
while 1:
line = f.readline()
if not f:
break
# process the line
whereas now it's
for line in f:
# process the line
As with all credos this should be approached with a large-ish grain of
salt and a pragmatic air. As with all Zen knowledge it's important to
avoid taking the Zen too literally, otherwise it may be necessary to hit
you on the side of the head with a stick to get you moving back towards
enlightenment <0.8 wink>.
We try not to be rude to perlmongers on this group. After all, they have
come much closer to world domination than we have so far, and they can't
help their peculiar penchant for coding in what looks like line noise.
[As you can see it's OK to poke a bit of good-humoured fun at them from
time to time].
Overall Python emphasises two things, readability and comprehensibility,
as primary values. Readability, comprehensibility and a welcoming
approach to newcomers ...
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list