PHP: Pimp-Hand Programming
I’ve said before that I’m a hater. What I haven’t mentioned is that I’m also a snob. Especially about programming languages. I’m not bragging – this is a personal flaw. My feelings about languages have changed dramatically over the years though. I still have languages I’d rather not work with but I’m finding that there is some value in almost any popular language you can name.
PHP was pretty easy to blow off when I first came across it back in 2000. It looked like the inbred bastard love child of ASP and Perl. (I think that is still an accurate assessment btw.) Back then I was already shifting from doing web apps in C++ or Perl to doing them with JSP or ASP. I didn’t need to learn yet another way to do the same stuff.
I did give PHP a try a few years later, around 2003. I installed a Slashdot-style app written in PHP which I planned to customize. I didn’t get far. The app turned out to have security issues. Major, major security issues which took out my fancy-schmancy leased server. This was during a time when I was trying to bootstrap a one-man startup. I recovered most of my data and I had backups for the most important things, but I lost my development velocity completely. Losing velocity can be death to any startup, but it was certain death to an under-funded one-man show like mine. I ran out of cash shortly after I was hacked. My attitude about PHP didn’t improve. Fair or not, I decided that PHP was for morons and it didn’t have the maturity required for real apps.
Time passed. Old wounds healed, and I finally started to get curious about PHP again. Last fall I went book shopping. I picked up a book on Erlang, one on Python, and one on PHP. It look me a while to get around to reading it, but when I did I was impressed. PHP can do all sorts of wonderful things.
Things that are good about PHP:
- The culture values simplicity and efficiency.
- It fills the gap left by classic ASP and it fulfills the same code-in-template need that ASP satisfied.
- You can run it from the command line. That makes it very test-friendly.
- It provides many features you’d want from an app server but it is still low level.
- It is fast.
- It’s available on a huge number of web servers in the world.
Of course PHP isn’t all puppies and kittens. Here are some things that are bad about PHP:
- It’s a screwy improvised language which tries to look like Perl but works more like C but also sometimes like Python.
- Its tag scheme sucks.
- There are many gotchas and not everything works as advertised.
- The learning curve is non-linear and downright rocky in places.
While I certainly do NOT miss Visual Basic or VBScript, I really, really miss doing apps in classic ASP. I used to be dead-set against systems that mixed programmatic code and HTML together in the same file. But after many, many years of doing it several different ways I have to say that I prefer the ASP way in many – if not most – common situations. Mixed systems like ASP or PHP require discipline to use effectively but they also offer great power and flexibility.
So I now respect the hell out of PHP. But there’s just no way in hell I’m going to use it for many projects.
Why? Because those many items on the “good” list don’t make up for those few items on the “bad” list. PHP can be fairly simple to work with, but when you least expect it PHP can be a fucking bear. Just the other day I spent 4 hours fighting with PHP to get a simple filter working with my blog posts. Wordpress is written in PHP and it lets you create custom filters. All I needed was some regex love in my filter. In Perl it would have taken me no more than 25-30 minutes. (And that’s because my Perl is rusty. If my Perl skizillz were current I would have been done in about 90 seconds. Seriously. It was a small task.) But I could never get it working the way I wanted it to in PHP. I eventually gave up and fell back to manual split/substr style filtering like I used to do when I was a newbie programmer and didn’t know any better. I’m almost as pissed about the inelegant solution as I am about losing 3-4 hours for no good reason.
This doesn’t mean I’m done with PHP though. I’ve been thinking about this for a while now, and I’ve come to the conclusion that PHP can be to the web what C is to Unix. Think of it as a portable assembler for the web. PHP runs everywhere and it’s fairly straightforward and also fairly low level. PHP also has some added mojo because it is naturally parallizable. PHP would make a wonderful target language for a “little language” compiler. Especially for a distributed solution.
I know that there is already Fogcreek’s Wasabi. But that’s not exactly what I’m talking about. Joel and Co. have solved only their own product problems and it sounds more like language translation than compilation. Wasabi (near as I can tell since it isn’t publicly available) doesn’t go all the way with the idea. I’m saying, GO ALL THE WAY. Make your own compiler that spits out PHP. I’m not saying compile Ruby to PHP so you can run Rails on it. That’s kind of nuts. (But hey, no one is stopping you.) Instead, I’m saying that you can take that custom DSL you created in Blub and implement it as your own little language. Have it output PHP and see what happens. That’s what I’m going to do. I think it’ll be a lot of fun.