Sunday, September 11, 2011

PHP Considered Inelegant

I'm looking at this year's SparkCon (2011) and noticed that the server had vomited on the sidebar. SparkCon's site apparently uses PHP to parse XML, and the parser threw an uncaught exception:


Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]:
Entity: line 1: parser error :
Start tag expected, '<' not found in /home/sparkcon/www/www/wp-content/plugins/gcal-sidebar/gcal-sidebar.php on line 369


Well, I'm not picking on SparkCon - it looks like a fantastic set of events - but increasingly I'm feeling less and less tolerant of those kinds of fit-and-finish flaws showing up when I'm interacting with a Web site.

Imagine what you would feel like if you were meeting a new business associate to chat at a cafe, and while you were talking they said "hold on...", unzipped, reached inside their undergarments to adjust themselves, scratched around for a while, and then tried to resume with "ok, go ahead".

We are all human, but some people are just more circumspect than others. That's why, intuitively, PHP rubs me the wrong way: inelegance.

Update: I'll give two examples. First, PHP's over-reliance on special characters and strings of special characters as operators in the syntax (from its Bourne shell -> ED/AWK/SED -> Perl heritage); and second, its concomitant reliance on gruesomely ugly idiomatic expressions for expressing trivial relations and operations. Neither of these PHP characteristics adds value to the solutions; both detract considerably from the readability of the code and add excessively to its code length. Since code-length is a correlate of error injection rate, PHP is objectively a worse basis for making an investment in code. 


I'm not sure if PHPs inelegance is entirely justified as a conclusion, but PHP isn't alone. PHP lacks the charming Rube Goldberg contraptions of Ruby metaprogramming, elegant to some but a sham to others. Perl is its ugly older brother, so ugly that it almost goes all the way around the ugly clock with one liners that appear elegant for how tightly they can compress their ugliness. And as bloated as the JVM platform has become, Java was not a particularly elegant language even when it started. JavaScript is like a fractured gem: turn it one way, and it looks elegant, turn it another and the flaws ruin the illusion. And then again, the apparent elegance of a language is not always sufficient to offset poor run-time performance.  PHP is just the scab I'm picking at today.


See also this tongue-in-cheek comparison

Post a Comment