Perhaps I am just dumb - On Perl, Python and context...
fperez528 at yahoo.com
Sat Feb 9 18:24:38 CET 2002
A little discussion on the issue of context which has been floating around my
brain for a while.
>> One of the basic philosophies of Python design is that it is wrong for
>> the language to guess when presented with something that's ambiguous.
> Which seems to be the opposite of the Perl philosophy - we will try to
> do the right thing.
Up front let me say I come from a background (in programming) of Perl (most
recently, lots of other stuff before that) and having switched to Python, I
refuse to go back. But I have given this particular issue some thought,
because it is highly defended by the Perl community and in the long run I
ended up understanding why *I* can't really live with it.
Perl is a language heavily inspired by one feature of human communication:
the usage of context to resolve the inherent ambiguity in language. L. Wall
is a brilliant man with a background in linguistics, and he has obviously
thouhgt this through and through, coming to the conclusion that using this
particularity of human languages in computer languages would be a good idea.
At first I thouhgt the same, loved it and enjoyed some of the benefits it
provides: conciseness, the immense expressive power of implicit knowledge,
flexibility. You can write three lines of Perl which, when resolved in their
current context, do amazing things.
The problem is, there is a fundamental difference between the way that
'context' is created in human communication and in computer languages. For
humans, context is something that occurs in *time*: you live through a
conversation, your mind is aware of that context, and therefore you can try
to resolve the ambiguities easily because you are immersed in the context.
This is precisely what makes an out-of-context quotation so difficult to
judge. In Perl, the computer doesn't have a problem because it *builds* that
context, via a complex set of rules, when it parses the code.
But now think of the human working in perl: when you are writing the code,
intensely concentrated on the problem, the context is clear to you. You use
all the power of implicitness, the decisions are -at the moment- obvious to
you and the result is beautiful, concise and powerful. Now it's 3 months
later, you haven't thought about this problem at all and you need to figure
out what the code does. Good luck. At first sight, the code will be ancient
egyptian: a magic incantation devoid of any apparent meaning. Until you spend
the time to rebuild the context slowly, carefully, you won't be able to
understand what the hell that code is supposed to do.
So in perl there are two options: either you maintain always the context
around your code as human readable information, in the form of detailed
comments, or every time you go back to your code you'll have to rebuild that
context by re-understanding the problem. That's why most of my old perl code
is either full of super-verbose comments or totally useless now.
Python is based on a fundamentally different choice: make each statement
explicit and clear enough that the chance for ambiguity is as small as
possible. This does mean producing slightly more verbose code, but in the end
I find it's worth it. First of all, because the conciseness of perl is an
illusion: if you want your code to be of any use in the long run, you better
comment the hell out of it. Not so in python, I have found that my python
code is very sparsely commented, yet extremely readable even months later. So
much for the conciseness debate. And the gains in clarity, reusability and
overall efficiency are priceless to me.
So in the end, this abstract discussion points to a very pragmatic
conclusion: I prefer python because I can be more productive *in the long
run* than I ever was in Perl. Maybe in Perl I can whip a 3 liner that does
something that will take a bit longer to do in python. But life is more than
3-liners, and it's in the big, complex problems that extend in time where the
differences really matter.
So there you have, my rather philosophical thoughts about the issue you
brought up. I know you asked about 'down to earth' information, and I hope
this doesn't discourage you :) Believe me, this newsgroup is *very* useful
for super-practical matters of syntax and semantics. It's just that many of
its participants are interested enough in languages that these
meta-discussions also generate quite a bit of postings.
More information about the Python-list