Python vs PHP (& Java?)

Alex Martelli aleaxit at yahoo.com
Wed Dec 27 04:45:06 EST 2000


"Ben Ocean" <zope at TheWebsons.com> wrote in message
news:mailman.977897649.4877.python-list at python.org...
> Hi;
> I’m an intermediate-level programmer that’s new to Python (via Zope) and I
> like it a lot. However, it appears to me that, while Python is a good
> replacement for Perl, it cannot replace much of the functionality of PHP,
> which can be scripted into HTML (whereas Python, it appears, must be

I'm not sure what you mean.  There are many setups which let you
mix Python code right into HTML 'templates', just as in Active
Server Pages (ASP's) or PHP approaches; for example, ASP's themselves
work fine with Python if your server is Microsoft IIS (using
Hammond's "win32all" extensions, or the ActivePython distribution
from ActiveState, you can install Python as an activescripting
language and call it from anywhere that supports activescripting,
which includes many important Microsoft applications & servers).

So, _what_ "much functionality" of PHP couldn't be "replaced" by
Python solutions?

> called). So, I have to wonder about the speed of Python vs. PHP for
> Internet-based applications. Python has the advantage of byte-code and
> compilation, but it’s server-side. PHP might not be as fast on the server,
> but it doesn’t have to make as many trips back and forth between server
and
> client.

Performance issues need good benchmarking practice.  But why would
a Python solution require any more round-trips than any other
server-side solution?!

> Plus, I’m curious as to why Python wasn’t written in such a way that
> it could be written directly into HTML documents like PHP. On a similar

What makes you think it wasn't?  As I said, there are many deployment
approaches that let you do that, if that's what your heart hankers for.

Of course, Python can be deployed in a zillion other ways as well --
it's not JUST for server-side scripting of HTML -- and in any given
case other deployment options might prove faster, more productive, or
whatever.

> subject, someone once informed me that Java was by far the best language
for
> scripting communication programs over the Internet (like chat, IRC, etc.).
> How does Python compare? Your comments are appreciated.

I've done a reasonable amount of Java coding, and, though it was a good
while ago, I don't think the net-oriented parts of Java have changed
by enough to modify my judgment.  My observation is that Java gave me
about 15-20% net programming productivity enhancement over C++ (being
an expert at C++, and relatively new at Java); Python, today, is giving
me about a range of 50% to 200% programming productivity enhancement
over C++.  Thus, although I have not tried out the *same* task in both
Python and Java, I confidently predict that Python would still let me
be MUCH more productive than Java would.

Just about the only plus for Java would be that a client's browser is
likely to have SOME Java version in it -- hard to tell how good or
updated it will be, but _some_ *very* elementary applets should work,
if you can bear to code at VERY, VERY minimal lowest-common-denominator
standards (be prepared to wave bye-bye to ANY productivity if you take
this route: just testing on AT LEAST half a dozen Java/Platform combos,
and empirically finding out just how low that lowest c.d. is going to
be, IS going to impact your productivity-to-deployment by an order of
magnitude -- if you're lucky).  With Python, assuming you want to do
distributed processing rather than just server-side, you cannot rely on
a deployment strategy based on 'everybody already having Python': you
have to get some Python installed on every target machine (Gordon McMillan
has a great program to let you prepare minimal installers for such
purposes).  On the plus side, for that one-time cost you gain much better
control on *what* Python versions are going to be on either side of the
communication channel, so the testing headaches go down A LOT (so much,
in fact, that you should consider a similar deployment strategy even for
Java or whatever else, even though it may not be as handy as for Python).


Do notice one thing -- if you master Python and its accompanying tricks
of the trade (e.g., preparing installers), there is almost no limit to
what you can do with it (excepting only computationally-heavy, and low-
level-system-programming, stuff; for which tasks your Python code does
need to be driving lower-level modules -- but there are a LOT of those,
free and high-quality, so the problem might reduce to finding the right
one:-).  Python gives you enormous leverage in the real world -- it
"plays well with others* in a way that no other language I know does.

Server-side scripting?  Python's great at that.  Need to work in a JVM
driving some existing Java classes?  Jython, the JVM-version of Python,
may solve that for you.  Network-distributed processing?  Python would
be my first choice for that -- take your pick of Corba, DCOM, SOAP,
HTTP, or Python-specialized approach such as pyro.  Need to script and
automate Visio or Powerpoint or Excel or some other MS app?  Python is
insanely great at doing COM Automation, too.  Heavy numerical processing
of big arrays of numbers?  Python, with the 'Numeric' module, is a
prime candidate for the task.  Symbolic and unlimited-precision
numeric computing?  PySymbolic and my own little gmpy at your service --
though they're pre-alpha, I'm told the speed already exceeds other
competing packages, and there may be further tuning soon.  Image
processing?  Why, PIL is the cat's pajamas.  Want to teach programming
to a total newbie?  Python's ideal for that.

It's hard to find a programming task for which Python is not among
the prime candidates (possibly with a leg up from some lower-level
module, see above).  How does it do it?  First and foremost, I think,
its *SIMPLICITY*.  If you follow this newsgroup for a while, you'll
see a zillion threads complaining about the lack of feature X, with
responses explaining why you don't really need X and/or how easy it
is to emulate it with Python's existing machinery.  If Python had
followed even just 10-15% of the suggestions/requests/demands for
such 'improvements' over the years, it would be just as big, complex,
unwieldy, and less-practical, as any other decent language.  But,
fortunately, the genius of Guido van Rossum, Python's inventor and
Benevolent Dictator For Life (BDFL), is in resisting such urges --
a unique mix of prudent conservatism, aesthetic intuition, and sheer,
clever practicality, which has permitted Python to grow into the
truly unique platform it is today.  Even he slips from time to time
(only one example of that, actually: the cursed "print >>" construct!-),
but one slip or so per decade is still a better batting average than
anybody else's!-).  And gradually, the whole 'culture' of Python has
grown up to realize this source for the language's strength and
support it intensely.


Alex






More information about the Python-list mailing list