Forwardslash /

TAGS: programming

In Defense of PHP

Sympathy for the Most Hated Programming Language

The culture, politics and aesthetics around programming languages is a weird topic not many can write about eloquently. I’m always intrigued to read an attempt to tackle that stuff and this blog is, among other things, my humble attempt at doing so myself. So the article Toolkits for the Mind, by James Somers in this month’s MIT Technology Review, caught my eye, and I was surprised to find there the best defense (or only?) of PHP that I’ve read.

The article isn’t just about that - it starts by talking about Ruby, and its creation as a kind of perfect instrument that would shape the user’s mind to enable it (or require it) to think about problems better. And it spends some time contrasting PHP with OCaml, a rigorous strongly-typed functional language flourishing in a financial systems niche. But the article is largely about the paradox of a language that powers the mighty Wikipedia, yet is “a shambling monster.”

I’ve been tempted several times to write a defense of PHP, because it’s been very useful to me, and because people hate it so much on the Internet. Then again I have to admit that I’ve had my own irritation with PHP, and since I started learning Python, have finally started to resemble the kind of language snob that just annoyed me when I was plowing through PHP code making custom WordPress sites. In other words, I agree the complainers have a point.

But Somers’ article is a well-argued reminder that it’s not purity, but flexibility that spells success for a language on the web. Because “despite the widespread contempt for PHP, much of the Web was built on its back.” Its easy productivity is linked to the loose, creative hacker culture that spawned some of the Internet’s biggest successes (namely Facebook), but also the biggest open source hits, like WordPress and Drupal. “PHP powers 39 percent of all domains,” Somers claims, and I would guess that at least half of these are WordPress sites. That’s a technology that has empowered millions of self-publishers, most of who could care less what code runs under the hood.

At the end of the day getting things done is what matters - and what other people have done, which you can use as building blocks to get you started. This is why web developers now are rushing to embrace another language they love to hate - JavaScript. Programming languages go in and out of fashion, and they also can get a boost. Google gave JavaScript such a boost, with its much-vaunted V8 JavaScript engine. Facebook is giving PHP a boost with Hack - also related to speed and performance, along with an additive approach to fixing some of the aspects of PHP’s design that make bugs harder to find.

Somers describes how startups will often add a new language to the mix when they need to scale up and grow up - one tighter and less hackerish - and cites Twitter’s infrastructure rebuild from Ruby on Rails to Scala. But their demands are in a far-off realm from most websites and even most web applications. In the meantime, PHP is always there for the legions out there who just need to get a website up fast. And for most cases, fast beats pure.