Monday, March 18, 2013

It's official: I hate PHP

I taught myself PHP sometime around August 2004. I was working for a tech firm in Belfast, a subsidiary of an American insurance company, and had just gotten shunted from the imminently-doomed tech support callcentre they ran into a software test position, mostly so the big boss could save face by keeping the job losses to a minimum.

It was, compared to everywhere I've worked since, a huge company with around 1200 employees. I was a very small cog in a very large machine, and for the first six months of my test position1 I had nothing to do. There were no projects small enough for a new guy to take on, and everybody else was too busy with the other stuff to train me. I was also at a desk in a different office from the rest of the team.

Left entirely to my own devices, I decided to teach myself PHP. I already ran a website, but was using entirely off-the-shelf stuff and didn't really know how to code my own stuff, so I decided to learn on the company dime.

Early results were, to put it mildly, not pretty. I'm sure if I was so inclined I'd be able to dig up some of the disastrous mess from a godforsaken hard drive, but I don't think anybody needs to see that. I was also trying to learn JavaScript and HTML at the time, and that was arguably even worse - I used tables for layout, for Christ's sake. For layout. Jesus wept.

Long story short, PHP was my back-end of choice for the next several years; I did get much better at it, moving through Wordpress theming and figuring out how to write unnecessarily complicated internal Realtime Worlds tools that never actually got used in the end. I must've been passable enough to get in the door at a real, actual web development company where I finally actually used OOPHP in anger.

A small aside: there's a big difference between writing stuff for yourself and writing it for a company. There's an even bigger difference when you're writing it for a client. The stuff I wrote for RTW at least was internal use only, and everybody there had realistic expectations for what was involved in writing it and what it would be able to do given the limited time available. Clients have no such limitations on their imagination. They want it doing everything yesterday.

When I moved to my current role, I had to pick up Ruby on Rails. There's a huge leap conceptually between a scripting language like PHP and a fullly object-oriented MVC framework like Rails2 - at least there was for me, having had little to no formal introduction to either.

Literally everything was different, especially given the server stack that was used. I'd never really done much Apache admin, but I had a rough idea where the configs were stored at least. Suddenly everything was nginx and unicorns, gemsets and bundles and rvm and capistrano - and I was using Linux into the bargain3.

Fast forward to today, and I've been using nothing but Rails for nearly two years. I'm sometimes astonished how quick I picked it up compared to PHP, even considering the additional experience I gained in the interim. It's so much faster to build with than PHP ever was, especially if you pull Twitter bootstrap in to create your views.

This morning I had to try and debug some PHP. A hacker had dropped some malicious code into a forum on one of our servers. It took two of us more than four hours trawling through the code (as well as updating the forum software) before we figured out where it was even being called; it was another hour before it finally got removed and the forum could be reopened.

Here is what I learned: PHP is a barren wasteland, lawless and without standards. It is unreadable garbage, especially if someone else wrote it for a forum plugin - God forbid anybody might ever want to understand what you're doing. I mean, my comments are far from perfect, but I at least try to be entertaining. And would it kill you to use descriptive variable names?!

I would happily never see another line of PHP code.

1 This is not an exaggeration - it really did take six months (and, I believe, a change in team lead) before I got any work to do.

2 I remember having a conversation, or maybe reading a blog posts, that made the argument that RoR isn't technically a true MVC framework, but it's close enough for my money. It's more of one than PHP anyway, which is the point.

3 It's a weird moment when you suddenly realise you've given up on the window manager because the command line is different for something. I still use the GUI to move files around (it's easier to undo if you make a mistake), but at one point I counted 17 open terminal windows on my work PC.

No comments: