Brian Krausz

I build internet things

PHP is a /great/ first language…for a hacker

October 6, 2008

So I figured I’d jump on the blogger bandwagon in the debate on whether or not PHP is a good first language.

First, a little context. PHP was the first language I did anything useful in. I learned QBASIC in middle school, which I used to make some neat games. Around 7th grade I taught myself PHP by hacking on phpBB installations. I didn’t learn any other language until college, where I quickly picked up Java, C, and SML (in that order). I agree that PHP is a horrible language to teach proper programming practices, but that’s not the point of it.

I’ve had the privledge of talking to Rasmus a number of times over the last few years, and while I didn’t get permission to reproduce his comments and so I won’t (I will say he has some funny stories about David Filo…), I can quote an article he wrote approx. 4 years ago on PHP:

PHP was never meant to win any beauty contests. … It was designed to solve a single problem: the Web problem.

It does this very well, as shown by it’s outstanding adoption rate. The truth is that PHP is hacky, but it’s hacky in a logical way. It was written to help a programmer have an easier time writing for the web by one in that exact situation, and it does it’s job. If you need to throw a page together in 5 minutes, you can do that! Which is exactly what budding programmers should be exposed to.

Think of it this way: why do people learn programming in the first place? Nowadays, it’s either as a career path, in which case they probably aren’t destined to be hackers in any sense, or because they need to solve a problem and writing a program is the best way to do it. What is going to turn a newbie on to programming faster: learning proper structure, or being able to pump out a solution to his/her problem in 5 minutes? I would bet a lot it’s the later. That’s what hackers do, they pump out a solution to a problem quick and, quite possibly, dirty.

“But Brian, have you ever seen dirty code?” you ask. Of course I have, and I despise it. But I contest that proper style is something that can be learned after the fact. The ability to pump out a prototype in 5 minutes can’t be learned as easily. The ability to ignore all convention and generate an import script to move all of your data from A to B to get your site back up, or hack together a script to bulk rename files in a really wonky way, while trivial to do for most programmers, can be done much faster with a hacker mentality.

I am a hacker, but I have no problem following convention. I don’t like to, since it slows down coding, but when I’m in a group of programmers, or working on code that needs to be maintained, I do recognize the point of doing so and follow them (to the letter even). Of course, I’m by no means the norm on anything, so take what I say with a grain of salt, but it seems to have worked well for me: I can follow convention, but at the same time I can adjust, I can change my style as the situation demands, and I can code up a storm when need be.

Share This Post