What is Python?

William Tanksley wtanksle at dolphin.openprojects.net
Wed Sep 20 15:07:18 EDT 2000


On Wed, 20 Sep 2000 17:14:05 GMT, Tim Hammerquist wrote:

>> But in terms of your point about "the best tool for the job", one _does_
>> have to admit in all fairness that there's at least _one_ thing that
>> Perl is an order-of-magnitude better at than Python: execute Perl
>> scripts.

>How 'bout regexps?

Perl certainly isn't an order of magnitude better than Python at regexps!

>Perl didn't create regexps, so why bag on them as some in this thread have
>done?  Unix operations demanded the existence of regex pattern matching
>and Perl, which was so obviously derived from several Unix tools,
>accomplishes them very well.  I've noticed Pythoners like to stand on
>soapboxes and look down on regexps. ("A true Python solution wouldn't use
>regex's.")

NONONO!  That's not what I said, and a TERRIBLE misreading of what I
meant!  Regexps aren't BAD; all I said was that they're not typically
Pythonic.  We don't look down at them; we just prefer to find other
solutions.  The reason for this is that we get SO many Perlers coming in
and solving simple problems in a complicated way with regexps.

In your case, I really do think that two regexps are a good solution,
since the thing you're searching for is unmistakably a pattern, and
furthermore a simple one.

>Why look down on something so powerful?

Because you only write one implementation at a time; it doesn't matter how
"powerful" the feature you use is if you only use it to do a simple thing.
It's better to use a simple feature that's designed to do what you need.

>Regexps are optimized for matching text against patterns as quickly and
>efficiently as possible,

Not true.  REs are designed for matching text against regular expression
patterns as quickly and efficiently as possible.  If your problem requires
an RE, use one; if it is weaker than that, consider something weaker
(it'll almost invariably be faster).  If it requires something more than
REs, check out the re library anyhow, because if enough people believe
that REs should be able to parse parentheses support will be added to the
library ;-).

>whereas you can only have so many:
>	if 'x' in word:
>statements before you're bloating your code unnecessarily.

We saw an example of this bloat just a while ago, when someone implemented
your search without regexps.  Someone preferring that mess to regexps
would be having problems.

However, the reverse is true; it's VERY easy to start using REs for
everything and ignore the fact that they aren't needed for most work.

>> show-me-a-language-that's-great-for-one-liners-and-i'll-show-you
>>    -a-language-that-doesn't-scale-well-<wink>-ly y'rs,

>Perl 5 took great strides toward scaling.  I would personally prefer to use
>Python for a larger scale app, but Perl is more than capable of doing it
>quite well.

I worked with a team which wrote a large Perl app.  It didn't go well.
Perl is capable of being used for that, but it's NOT capable of doing it
quite well; it just requires the programmers to spend too much time
setting conventions in order to make their code interchangable enough to
mix well.

>-Tim Hammerquist <timmy at cpan.org>

-- 
-William "Billy" Tanksley



More information about the Python-list mailing list