newbie questions (Python vs. Perl)

Lars Marius Garshol larsga at ifi.uio.no
Mon Apr 5 03:26:22 EDT 1999


* Phil Voris
| 
| 1) I hear it's the best for learning OO. 

Maybe. Personally, however, I think that when learning OO it doesn't
matter all that much which language you do it in. All you want is
basically that the language stay out of your way and let you get on
with the learning.

As such, I think maybe Simula would be the best language to learn OO
in.

| I have heard high praise of Eifel as well, but information on it
| seems to be scarce at best. 

Try this URL:

<URL: http://www.cm.cf.ac.uk/CLE/>


Here you'll find lots of informationa and links to other useful
pages. You can also find some useful tutorials.

However, I don't think Eiffel would be a good learning language. I
tried it and found it difficult to get started, and I also think you'd
do best to stay away from this design-by-contract until you understand
OO.

| (I have C and Perl experience) Will Python take me to the next level
| in terms of understanding OO?

You might go there with Python, but it won't do this automatically for
you.
 
| 2) Use in the 'real world.'  Are companies really using Python?

Sure. I work at a company which does, and we're very happy with it.
You'll find some references at the Python web site as well.

| Articles suggest that Python is preferable to Perl because it's
| better for prototyping and more suitable for team projects (than
| Perl).  In your opinion(s), has this been a major factor in choosing
| Python, or is it more enjoyable to program in (than Perl)?

We chose Python simply because it was a better language. Easier to
build large programs with good structure, more predictable syntax,
easier to learn, easier to catch bugs in etc etc
 
| 3) Speed.  How much slower is Python than comparable Perl? 

Yes. More or less. Maybe. Not at all. 

It depends to a very large degree on what you're doing and how you do
it. In general I don't think the speed difference is an issue.

| I have read about compiling Python as C or Java and ask myself how
| this code compares to code written directly in those languages.

The Python2C compiler I haven't tried, but JPython is slower than both
pure Java code and CPython. Again, the exact amounts will vary.

To take one example, I recently heard from a guy who'd written a
performance-critical function in Common Lisp that executed in 623 µs
per call. He has a C version that takes 92 µs per call, but after
heavy optimization he now has a pure Common Lisp version that executes
in 4.7 µs per call.

His conclusion was that although the first attempt was likely to be
faster in C, Common Lisp made it far easier to try out different
strategies and algorithms, so that achieving 5 µs performance required
less effort in CL than in C.

I think you'll have similar experiences with JPython and CPython.
Usually it's fast enough. When it's not you can usually tune it quite
a bit. If that doesn't help you usually at least have a very good
algorithm, that you can then translate into C/Java. Predicting the
performance ratio of this version against C/Java code I find almost
impossible, since performance is to some degree a function of expended
optimization effort. (It's also usually related to your choice of
language implementation.)

To take another example, I've written a validating XML parser in
Python, which I've spent quite a bit of time optimizing since version
0.50 (which was unoptimized). Version 0.50 chewed through my benchmark
suite in 49 seconds when not validating and 599 seconds when
validating (one document has a 2K document and a fiendishly complex
79K DTD).

The version currently in my CVS tree does the benchmark suite in 21
and 48 seconds respectively, and I still haven't tried rewriting any
of it in C.

So a fixed comparison ratio between languages is at best useless and
probably misleading.

--Lars M.




More information about the Python-list mailing list