Jeff Atwood says that it doesn’t matter that PHP sucks. Well, he’s right and he’s wrong.
Let’s analyze it.
PHP has a few things going for it.
1. It performs well on the “Hello, World!” test.
Pro: Writing a simple program is simple and straightforward. Con: None. Bottom line: It’s easy to start seeing results.
2. PHP lets you embed HTML in your code cleanly and simply.
Pro: No need for other template languages. Con: Strong temptation to mix display and logic code. Bottom line: It’s easy to start seeing results.
3. In general, PHP is one file per URL.
Pro: A big win for finding the code you’re looking for. Con: Makes for lots of spaghetti/duplicated code code. Bottom line: When there’s a problem with a page, you know where to look.
4. It’s installed on most commodity web hosts.
Pro: Lots of hosts to choose from—your code will run anywhere. Con: None. Bottom line: You can choose the host you want.
5. Gigantic user base.
Pro: Bugs are worked out. Lots of documentation. Lots of libraries. Con: None. Bottom line: All of your questions are answered.
These things help you build a site fast.
PHP sucks for a number of reasons:
1. No powerful abstractions.
You can’t do much more than procedural abstraction. OO in PHP is crude. Code size is directly proportional to software complexity. Good luck doing anything complex.
2. Horrible library design.
The functions are horribly named. It’s just one flat namespace. Good luck guessing a function name.
3. Big ball of mud methodology.
Once your code gets complex, you have to start splitting your code into multiple files. Good luck finding your code now.
What this all amounts to is this: It’s easy to write a simple site. It’s hard to write a complex site.
Jeff gives some examples of huge, successful sites that use (or used) PHP. YouTube, Wikipedia, Digg, Wordpress, Facebook.
I’ll address Wordpress last, because it’s different. Wordpress is software you install on your own server. But the rest are basically just a few dynamically generated pages.
The other sites, I argue, are not very complex at all. Every time I use Facebook, I marvel at how simple it is. I always think to myself: wow, this is such a simple site. It feels like it’s just a handful of PHP scripts. And it probably started that way.
YouTube is just a home page, some configuration pages, and the video pages. The real magic of the site is the flash video player. The rest just seems like commodity features you can find anywhere.
Wikipedia probably has the most complex software behind it. But it, too, doesn’t do anything revolutionary.
I don’t think I’ve ever used Digg, so I won’t comment.
Wordpress is great software. I still use it. It’s got some good features, but most features don’t extend beyond one page. That is, each piece of user functionality requires a separate PHP file.
The real value in YouTube, Wikipedia, Facebook, and Digg are their marketshare. Their user base. They do a couple of simple things well. They do the right things well. And they have lots of users.
They are (arguably) revolutionary. But it wasn’t because they are built on complex, ground breaking software. They changed the game because they do something simple that everybody wants.
Wordpress is easy to install on basically any web host. The install is butt-simple. That’s its advantage. And it does all of the things everyone expects from a blog.
Jeff posits that “building a compelling application is far more important than choice of language”. I have to agree. You should prioritize functionality over language choice.
But his second conclusion that “sufficiently talented coders can write great applications in terrible languages” is somewhat misleading. The examples he gives are great and are written in a terrible language. However, this does not mean that every great application can be written in PHP. Only some simple applications can be written in PHP.
So my conclusion: PHP sucks, but it doesn’t matter for some applications. If you want to write a quick, one-off database-driven app, use PHP. If you want to do anything more complex than that, pick a different language.
