Why should i use python if i can use java

Alex Martelli aleaxit at yahoo.com
Thu Jun 7 04:39:42 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:9fm97b05cl at enews1.newsguy.com...
    ...
> And higher productivity.  I thought I had posted a huge treatise
> on that just a few hours ago to a heavily crossposted thread
> with a funny subject about 3D, but it doesn't seem to have
> shown up, I'll have to look into that... it mentioned Prechelt's
> empirical study, quoted Eckel extensively, etc, etc.
    ...
Seems to have disappeared, so, here we go again:


> I admit, often Java is slower than C++, but whether your keystroke
> will get displayed after 10ms or 20ms within a text editor doesn't
> play any role, does it?

It doesn't -- which is why one should use highly-productive
Python (or Jython, if you prefer to have a JVM underneath --
it's the same language either way, in one case you use fine
tuned C-coded libraries, in the other any Java library) for
as much as possible of one's applications (typically around
90%, depending on the kind of things you do -- the other
10% [may vary from 0% to 30% on different classes of apps]
is too speed-critical).


> Cross-platform development and the ability to have a running BETA
> program before C++ programmers even have a concept.

Have a look at (a preview of) Bruce Eckel's forthcoming "Thinking
in Patterns" chapter 9, e.g. at
http://www.cis.ohio-state.edu/~cguo/books/ThinkingInPatterns/html/Chapter09.
html
(there may be better-updated versions).  Eckel, of course, is
quite a Java enthusiast, best-selling author of "Thinking in
Java", etc, etc.  He writes as the chapter's conclusion:
"""
To me, Python and Java present a very potent combination for
program development because of Java’s architecture and tool set,
and Python’s extremely rapid development (generally considered to
be 5-10 times faster than C++ or Java). Python is usually slower,
however, but even if you end up re-coding parts of your program
for speed, the initial fast development will allow you to more
quickly flesh out the system and uncover and solve the critical
sections. And often, the execution speed of Python is not a problem
– in those cases it’s an even bigger win. A number of commercial
products already use Java and JPython, and because of the terrific
productivity leverage I expect to see this happen more in the future.
"""

I fully concur with his evaluation of a 5-10 times productivity
advantage for Python vs C++ (speaking as a C++ expert here) --
in my (more limited) experience with Java the productivity
advantage wrt C++ was about 20% to 30%, so (if this holds on
a wider field of applications) the Python/Java ratio would
be more like "just" 3 to 8 times the programmer's productivity.

The ratio in terms of *numbers of line of code* (a VERY rough
measure, but known to hold surprisingly well as a measure of
"language level" -- lines of code per Function Point -- and
thus, indirectly, productivity in both development _and_
maintenance phases) tends to be on the order of 5/6 times
as many lines of Java (or C++, assuming one IS using rich
libraries, such as those at www.boost.org, wxWindows, &c)
per line of Python -- and note that Python does NOT come
from a "one-liner culture" a la APL or Perl:-).  Very roughly,
this would seem to confirm the order of magnitude of
productivity advantage (assuming speed concerns do not
interfere and need re-coding of some parts, which would
push development times closer together).

Prechelt's empirical study (there should be more of those
in this field...!-) gives more nuanced results.  He
grouped several language into two groups, and he only
was able to observe smaller differences.
http://www.ubka.uni-karlsruhe.de/cgi-bin/psview?document=ira/2000/5
is one URL where you can find the full article in several
formats.  Summarizing conclusions:

He noticed a programmer-productivity advantage of about
a factor of 2 for "scripting" (Python, Perl, Rexx, Tcl)
vs "compiled" (C, C++, Java).  Typical memory consumption
for script about twice that of c/c++, for Java another
factor of two higher than script.  Initialization-phase
performance, C/C++ about 3/4 times faster runtime than
Java, about 5/10 compared to scripts.  Main-phase
performance, C/C++ about 2 times faster than Java,
Scripting also faster than Java.  Python and Perl
always faster than Rexx and Tcl.  Variation in all
performance measures is larger between programmers
in the same language, than between groups of programs
in different languages (man still counts for more
than machine:-).

One little detail -- 80 programs in all were examined,
all solving the same problem -- 5 in Rexx, 8 in C, ...
up to 26 in Java (Java most popular).  Totally unusable
programs were as high as 3 in 8 submitted in C (so all
the rest of the study including the above conclusion
only studies the other 5:-), 3 of 14 in C++, 2 of 26
in Java.  Python (0 unusable programs out of 13 that
were submitted) was the ONLY language in which *NO*
unusable programs were submitted.  Statistical fluke,
no doubt, but...:-).

For performance, see in particular:
http://www.ubka.uni-karlsruhe.de/cgi-bin/psview?document=ira/2000/5&format=1
&page=14
You'll see the Rexx horrid-performance is dragging
down the "Script" group all by itself.  Examining
language by language, one can get an idea...:-).


Alex (Brainbench MVP for C++, but Python enthusiast:-)






More information about the Python-list mailing list