Python vs. Perl
Perl folk seem not to like Python, at least not at first glance.
It's easy to understand why: the languages serve similar purposes,
but have annoyingly different syntax and structure. There have been
converts, though, and Eric S.
Raymond's experiences are probably not atypical.
I've noticed that Linux
Journal has had more than a few Python articles, and the most
recent issue has begun a tutorial series. That article prompted me
to take a more serious look.
I went to http://www.python.org/doc/current/index.html
and used the excellent tutorial there. I found things to like and
things to dislike immediately:
- That object methods are the default, not something tacked on:
print "Before Append",a
print "After Append",a
Before Append ['abc', 'def', 'ghijkl']
After Append ['abc', 'def', 'ghijkl', 'hello']
There's a whole boatload of built-in methods: see http://www.python.org/doc/current/tut/node7.html.
I'm not going to say I like these better than the Perl functions
that do similar things, but I certainly have no problems with these
and can see good use for them.
- That integer math is the default unless one or more of the
operands isn't an integer:
print 7 / 2
print 7.0 / 2
- That semicolons at the end of lines are optional: any of these
print 7/2;print 7/2.0
Leaving off semicolons is a common Perl goof..
- Indentation syntax. Everything indented is part of what happens
when "mytest" is not 0 or null:
print "mytest ",
print "is set"
print "hello ",
Oddly, this is something most Perl types really hate, but I'd
find it easy to get used to. Since most of us tend to indent code
within blocks anyway, it seems reasonable to me to dispense with
the braces and just use the indentation.
- Default argument values for functions:
def foo(prompt="huh?", count=2):
I really like that.
- Exception handling. I like "try/except" logic (apparently Perl
6 has this too);
- Variables. I don't like the C-ish variable names. I LIKE that
Perl requires a $, @ or whatever ahead of a variable name - it
makes it stand out. I also like that Perl's $a is different than @a
- Data types. Setting a one value tuple is absolutely ugly:
print this, len(this)
this='hello' # NOT a tuple
print this, len(this)
this='hello', # Now it is
print this, len(this)
('abc', 'def', 0) 3
This is a consequence of not having data prefixes or formal
- No "a++" or "a--". Sheesh.
- No "$_". There's _, which apparently isn't quite the same -
unless I misunderstand, which is certainly possible at this
Overall, I think I'll stick with Perl. I can see Eric Raymond's
argument for larger projects, but I don't do large projects anymore
and I just find Perl's wild versatility and lack of insistence
(More Than One Way To Do It) more attractive than more structured
languages. But Python certain does have its appealing aspects, so
I'll probably dabble with it here and there.
I certainly cannot agree with some who insist that Python is
easier to read or understand than Perl. That's just ridiculous:
neither of them add anything to helping understand someone else's
code. Perl isn't any more "cryptic" than Python. Nor can I
understand the attitude that Perl is deficient because you can do
things in multiple ways. If you insist on such structure, enforce
it upon yourself: nobody is stopping you. I do understand that for
larger projects, with multiple people involved, structure is more
All in all, I wouldn't be terribly upset if I got "stuck" with
something that had to be done in Python. It's a very reasonable
scripting tool and does have some very nice features.
If this page was useful to you, please help others find it:
More Articles by Tony Lawrence
- Find me on Google+
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site:
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Publishing your articles here
Jump to Comments
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.