altre destinazioni

ultimi post

ultimi commenti

tag principali

categorie

archivi

powered by

  • WPFrontman + WP

friends

copyright

  • © 2004-2011
    Ludovico Magnocavallo
    tutti i diritti riservati

Python never had a chance against PHP?

30 marzo 2005

0 commenti

categorie

As much as I usually like John Lim’s excellent PHP Everywhere, I don’t particularly agree with his comments on Ian Bicking’s Why Web Programming Matters Most. Being a longtime PHP programmer (since when it was called PHP/FI) and PEAR contributor, and having heavily used (and loved) Python for all my projects in the past couple of years, both Ian’s

resolving Python’s problems with web programming is the most important thing we can do to market Python

and John’s

what made PHP successful is not what PHP is lacking but the features that PHP has that are superior to Python

ring true to my experience.

What I don’t particularly agree with is John’s list of things PHP “does better” than Python:

  • Python is not a template language. Even though the “templating” nature of PHP makes it easy to use for casual programming, it soon becomes a real PITA even for smaller applications
  • Python is a so-so string processing language. Python is a much better string processing language. I find 'abcd'[:2] much more readable than substr('abcd', 0, 2), and "aaa%saaa" % var much cleaner and less error prone than "aaa${var}aaa". The list could go on with triple quotes, raw strings, Unicode support, etc. In fact, Python’s string processing is one of the many things I miss in PHP.
  • PHP’s documentation is cleaner and much easier to understand than Python’s. I don’t think PHP’s documentation, or PHP itself, are “cleaner” than Python. Just compare the myriad of array functions in PHP with the mapping methods in Python, which fit in a single HTML page. With PHP documentation, you often have to resort to reader’s comment to understand a function’s behaviour, something which (almost) never happens with Python’s docs. My understanding is that people are intimidated by the number of libraries included with Python, and never take the time to learn the basics of the most important ones, thus missing the key section of the docs. And it also seems that nobody knows there’s the PQR around.
  • PHP has tighter integration of a lot of web related stuff. Even though PHP’s _ vars (_REQUEST, _SERVER, etc.) variables are very useful, I don’t see much difference in having them available as eg a request object’s attributes.

The key PHP advantage is, in my opinion, just one: the tight integration with Apache, and the flexibility it gives you in deciding where your code goes and how it gets executed. The ability to scatter a bunch of PHP files around, to use a hierarchy of directories, to put “static” content alongside your code, those are the features that make PHP web programming a joy. Oh, and PHP’s speed, which seems to be far greater than Python’s at web apps.

In all other respects, Python beats PHP hands down: code quality and functionalities available in the included libraries, design cleanliness, unified DB API, namespaces, proper types, the list could go on for half a page.