Sunday, April 08, 2007

Lack of elegance is viral

I've been playing with PHP to build a simple web app. Amazingly, I've never really used PHP before. I have toyed with it (as well as many other many other web frameworks)but little more. Many years ago, I made my living writing Perl CGI scripts, but the state of the art has made some serious advances since then. PHP is not one of them.

PHP did make me realize just how spoiled I am. Programming in PHP makes me feel like I'm back in college, where I don't know the idioms and have half-baked libraries. The PHP language isn't really any worse than Perl. The PHP libraries are amazingly rich and I bet I could find something that could find the solution to world hunger somewhere in there. But that hints at my first problem with PHP. How the hell do you find the right library for your problem? It seems like there are 2 implementations of everything, probably because nobody could figure out to find the first implementation. There is absolutely no standardization across the APIs. The documentation is impressive in its quantity, but definitely not it's quality.

The biggest problem? All this ugliness encourages ugly programming. The best way to encourage good programming is a framework that is itself elegant. This is a large part of why Ruby (and Python) have such a following. I would argue that framework elegance is more important than anything else. PHP's mess encourages ugly programming because that the whole language/libraries collection is ugly. It is so hard to write clean code when every library call interrupts the flow.

This is one of the reasons for Lisp's cult following. You can mold the language to fit your purposes. Good code is about clean flow that makes the the logic of the code clear. When I look at the PHP code I tossed together, the presentation logic and the app logic are all a giant pile of ugly mush. While building and testing my trivial app, I would make stupid mistakes simply because I could barely read the code.

Ruby on Rails has gotten a lot of press as the future of web app development. I've seen startups advertise their use of Ruby On Rails as a hiring tool. A lot of people have weighed in on why Ruby and Ruby on Rails has garnered such attention. I think the reason is that the core language and the Rails framework are good examples of elegant design that encourage elegant application code.

1 Comments:

Anonymous Anonymous said...

The PHP language isn’t really any worse than Perl.

I take umbrage at that claim. PHP is definitely far worse that Perl. Perl is just as clean as Ruby or Python – if anything bedevils it, it’s an image problem. Perl 4 and earlier were limited languages; and when Perl 5 was new, all the kiddies that cobble together PHP into barely-running code today used Perl. So the impression has stuck that Perl is an ugly write-once language. We’re struggling to get people to notice there’s more to web apps in Perl than CGI.pm kludges; the Perl-side equivalent of Rails for Ruby, Catalyst, is older than Rails.

However, I am somewhat ashamed of linking that site, and if you follow that link you’ll immediately see why: it’s pants. 37signals never made that mistake; their marketing of Rails has been top-notch from the start. I don’t say that as a put-down; that Rubyistas managed to sell the world on the ideas behind Rails is a net win for us, and that we over in the Perl side failed to do the same is – besides prejudice stacking the odds against us – a failure on our part. I don’t begrudge Rails its success: I would happy to be writing Ruby or Python, even though I prefer Perl for various (and largely benign) reasons. I just resent people looking down on Perl based on prejudice that has been obsolete for over a decade, if it was ever valid.

All that said, I agree with the main thrust of your argument that inelegance breeds inelegance, and that this is a pervasive problem in PHP.

7:03 PM  

Post a Comment

<< Home