Sam says you should read this
This blog was created with the BlogFile software, written by Samuel Levy.

You can find Sam on Google + and LinkedIn.
 

Why PHP?

This is a question that people ask me every time I release a small project (like BlogFile) in PHP. There's often assertions made that I should "learn a real language", like python or ruby. There's a bit of general PHP hate ("I'd rather stab my eyes with hot pokers than use PHP"; "PHP is to programming what nails through the genitals is to sex"; I have some inventive friends). In general, it always boils down to one question: "Why PHP?"

Now I'm not unaware that PHP has it's faults. Every time I'm working on a larger PHP project and try to build better objects, I run into issues with the PHP Object model. If I know a new project will be large or long-lived, I'll usually go for python (with either Django, or more frequently Pyramid). I am well aware that in the hands of the inexperienced developer, PHP can be slow, ugly, and at times downright dangerous.

There's one thing that PHP offers me in a way that no other language does, though.

Fun.

That's not to say that I can't have fun with python or one of the number of other languages that I use. They do offer me the type of fun that you might get, say, from a dinner party with friends, or a weekend camping trip. It's a safe fun, but it requires planning, preparation, and you know that if anything goes wrong you can probably think it through and come to a logical solution.

Sometimes I just want to jump off a waterfall, or ride my bike down a mountain. I'm not looking for safe; I'm not looking for prepared; I'm looking for the thrill - the rush of diving in to something messy and getting out the other side. Maybe I'm romanticising it a bit, but that's ok; if everyone else is allowed some hyperbole, so am I.

PHP lets me open a file, bash out a project, and start showing people my crazy idea in the shortest time possible. I don't need to worry about setting up a framework, or a clean workspace, or downloading dependencies. My workspace is an empty folder, and my framework is the language itself. Sure, it might not scale but I'm not trying to run a business with it. It might be a mess of code, but the idea is testable (sometimes within minutes) and it takes no more than an upload before I can start showing people. If the idea is solid, then it's not too hard to rebuild it in another, more sustainable language; the logic has been figured out and tested already. If the idea turns out to be crap, then I've lost less time than it would have otherwise.

It's more than just the fact that PHP is great for prototyping, though. PHP makes writing clean code a challenge, which makes me truly evaluate how important building some features really are. Following the logic of a PHP program can be difficult, so it makes me think about how to make everything as clear as possible.

If I had spent most of my time writing Java, I wouldn't write nearly as much (nor as good) documentation as I do. I wouldn't even be writing half the code; boiler-plate and an IDE would do most of it for me. Because I had experience writing in other languages before I came to PHP, I've come to realise how important code structure, documentation and owning your code really are.

None of these are really reasons why you should use PHP for your projects. These are the reasons why I use PHP for mine. I'm not trying to argue with you about name spaces, or static typing, or the horrible mess that many large PHP projects become. I'm not saying that PHP is a perfect language, or even well suited to many of the tasks that it's used for. I'm saying that to me, PHP is the extreme sports of the web programming world. I have fun with it in a way that is unmatched by any other language (JavaScript is close, but in the "client side" form, not Node.JS).

Sure PHP is ugly, and weird. It'll also be here for a long time, and I love it for what it is. I'm sure I'm not the only one.

P.S. It probably didn't help that I was listening to "Wish You Were Here" while writing this. That always makes me get a little "Shine On"

Comments have been locked for this post.

couldn't agree more

 
Screwtape

"PHP as extreme sport" does make a lot of sense, when you put it that way - it's like talking to somebody who does skydiving and saying "why would you jump out of a perfectly good aeroplane?".

On an unrelated note, the CSS for this site gives the #maincontent div height: 100% and a 20px bottom margin, which means that Firefox gives me an extra scroll bar so I can scroll that blank 20px into view. If you removed that margin, I'd only have one scrollbar and I'd probably be a lot less confused. :)

 
Samuel Levy

That's fixed now, and I've fixed some issues with phones, too.