[vox-tech] python: slicing extensions from file names

Micah J. Cowan vox-tech@lists.lugod.org
Wed, 30 Jul 2003 09:31:13 -0700


On Tue, Jul 29, 2003 at 05:08:50PM -0700, Dave Peticolas wrote:
> On Tue, 2003-07-29 at 16:57, Micah J. Cowan wrote:
> <major snippage>
> > Actually, most of the time I personally prefer C or C++. But if I want
> > a higher-level language that allows me to finish faster in exchange
> > for less efficient programs, less direct control over what's
> > happening, and the requirement that an implementation be present on
> > the end-user's machine, then assuming I knew Python quite as well as I
> > know Perl, I would usually use Perl for doing stuff that had any kind
> > of major text processing, and Python especially for GUI-oriented
> > things.
> 
> I don't think Perl is all *that* much better than Python
> for text-processing. Python's re module is usually on a
> par with Perl's. And the cleaner code of Python is a
> major bonus.

In my experience, it is better in a lot of little ways. A lot of
little ways adds up to something significant. And the difference
between a built-in RE engine and a module is significant to me as
well. One of the biggest things to me is that, even when taking into
account OO programming, I can generally get things done in fewer lines
of code in Perl, without sacrificing legibility.

Of course, when we talk about Python code being "cleaner" than Perl's,
this is really a shorthand phrase for something a little more complex,
since obviously code in both languages is going to vary
person-to-person. What I mean when I say that is that Python's
syntactically significant whitespace forces you to break things up
quite nicely, removes the need to scan for braces, and gives the
programmer absolute assurance that program flow really does follow the
indentation. A good Perl programmer can still code with all of this
(except the braces, which is a very small thing, and provided the
indentation is consistent, the braces cause no harm), and will forsake
"clever" single lines in favor of more legible, multi-line examples.

There are a lot of ideas that Larry Wall incorporated into the
language that I deeply admire: for example, the idea that the things
you use most often should be the easiest to type (which is one of the
reasons I believe that Perl can be a little quicker to code in,
particularly for text-processing-heavy work).

And for me, at least, the main reason I use Perl is that it is *fun*
to work with. I haven't had quite that much fun in my dabbles with
Python. YMMV, naturally--that's what makes individuals individuals.

The only things I *really* wish I could get with Perl is: I wish it
had exceptions, and I wish I could choose the strength of the typing
(obviously, I could write ties which would ensure correct values,
but...). Both of these will be introduced satisfactorily in Perl 6, I
believe.

> > Depends on the text processing, though: I find that
> > character-by-character access of a text string is somewhat less
> > painful in Python compared to Perl. It always seemed kind of strange
> > to me that there wasn't a straightforward C-array-style access to
> > strings, or something similar, in Perl.
> > 
> > Pet peeve about Python is probably the braindead scoping
> > rules. Lexical scopes are not nested: when you enter a block within a
> > block, the outer block is completely and utterly obscured.
> 
> Yeah, but that was fixed in Python 2.1, released 2 years ago.
> Python now uses regular lexical scoping.

Really? I'm very glad to hear that.

At any rate, my point is simply that Perl and Python are both very
useful tools, and which one to use really depends a lot on your needs
and values for the particular project.

-Micah