| ★ wanayoo — archive 1999 http://www.perl.com/pub/language/versus/python.html | Nouvelle recherche | Portail wanayoo |
![]() |
|||
|
Perl vs. PythonForwarded: Fri, 02 Jun 95 06:40:58 MDT Forwarded: guido Return-Path: tchrist Fri From: Tom Christiansen In comp.lang.Perl, efp@mindspring.com (Eric F. Palmer) writes: :I was recently looking for a Perl interface to Illustra an Object Relational :Database when someone suggested that I use Python to interface to the DB not :Perl. : :I had to pleed ignorance as to what is Python. I have since learned that it :is claimed to be somewhat similar to Perl only more fully object oriented. : :Can anyone shed some light on Python and how it compares to Perl. Python is a well thought-out, interpreted, byte-compiled, extensible, largely procedural (imperative) programming language good at text processing and sometimes even general-purpose or GUI programming -- just as Perl is. It was written by one of the ABC authors, Guido van Rossum. For most people, it's a much more serious and reasonable language for applications development than a glorified macro processor full of string-substitution problems like tcl, nor an ivory-tower nest of crazy parens and functional programming like scheme, both of which make Perl and Python seem like breaths of fresh air for a lot of folks. If Perl weren't around, I'd probably be using Python right now. It isn't used by very many people, though. Python does not resemble C very much, nor in fact does it resemble awk, sh, sed, or any other Unix utility really at all (whereas Perl does). It doesn't have assignment operators or autoincrement operators or anything like that, all of which seem to deeply confuse non-C programmers. Both have an interactive mode for easy debugging. Python was designed ab initio to be object-oriented and have clear module semantics (although I think some folks find the namespace games messy). It is nearly as fast as Perl, but doesn't have so powerful regular expression stuff as Perl, nor does it have function pointers with deep binding (read: closures), and a variety of other things I forget right now. The Unix interactions Perl is so good at can probably be taken care of in Python using the proper extension module (beware though, as that's what they'll say about extended tcl in incrtcl as well, and down that path lies madness). I'm pretty sure there's no way to take a pointer to something: it's all implicit, for both good and bad. I'm not sure what if anything at this point Python has that Perl doesn't. One of those most annoying things about Python for many people is that it intuits block structure from indentation alone. Its loops look like this
while 1:
buf =index.html fp.read(blocksize)
if not buf: break
conn.send(buf)
In Perl, that would be
while (1) {
$buf = $fp->read($blocksize);
if (not $buf) { last }
$conn->send($buf);
}
Another thing people consider a feature in Python over Perl is that no one is ever going to turn around and write the whole thing in an entirely different way as they might in Perl, eg:
LOOP:
while (1) {
$buf = $fp->read($blocksize);
if (!$buf) {
last LOOP;
}
$conn->send($buf);
}
or
while (1) {
last unless $buf = $fp->read($blocksize);
$conn->send($buf);
}
or
while (1) {
last unless $buf = read $fp $blocksize;
send $conn $buf;
}
Actually the last one isn't likely to quite work due to built-in definitions intentionally difficult (but not impossible) to override. Don't screw up on indentation though, or you'll screw up on blocks! Perl at least fixes C's ambiguity by REQUIRING curleys for blocks. This seems to help a LOT of people. Python also tolerates newline as a statement separator. That means that you're going to have to do some surprising things at times. For example this:
a = 3 * 5
- 12;
won't work.
In summary, there's a great deal of overlap in functionality between the two. The extent to which you prefer one over the other will probably depend on how comfortable you already are with C and Unix shell programming in general. It may also depend on whether they're already a library written (or a primitive) to do what you want, like database manipulation, math stuff, forms entry, graphics (windows or pixels) extensions. Perl is also a bit older and far more widespread than Python, and Perl ships with a number of vendor systems. Partly because of the huge body of code out there that people have already written and partly due to its propensity towards addressing these problem domains, you'll find a working knowledge of Perl to be a mandatory job requirement at many sites for system administrators, database administrators, toolsmiths, support and test engineers, and WWW maintainers, just to name a few. --tom [There that wasn't a flame, was it? (at least, not against Python :-)] Copyright 1996 Tom Christiansen. All rights reserved. |
|
|
![]() |
||
| DOCUMENTATION DOWNLOADS CPAN FAQs MARKETPLACE SEARCH REFERENCE CONTACT US | |||
Compilation Copyright © 1998-99 O'Reilly & Associates, Inc.