Loving PHP in a hostile world

Reading the comments and blogs that pop up on reddit, I’ve found that a furious animosity exists towards the good ol’ PHP Hypertext Preprocessor. Any mention of PHP is met with a firestorm of derogatory remarks; the community consensus seems to be that the language is used only by the worst class of shit farmers, harvesting crap from the reeking soil with crude fecal trowels.

Using advanced data mining techniques, we can determine where PHP might stand in terms of programming language hatred:

Google Suck-Off
“java sucks” 20,100
“C++ sucks” 8,670
“php sucks” 7,730
“lisp sucks” 3,550
“ruby sucks” 2,230

One might expect phpsucks.net to provide an explanation for why the language is hated, but the site has a decidedly different message. If you want coherent, technical arguments against PHP, then certainly they exist. Here are a couple of decent ones that I found with a cursory search:

And yet, the language is not without modern-day success stories: 7 reasons I switched back to PHP after 2 years on Rails.

Having used PHP with varying degrees of intensity since 1999, I find that I still love hacking in the language. My programming skills have matured greatly over the years, and PHP in no way prohibits me from writing the well-engineered code that comes with that maturity. You don’t have to express your application in some mucous HTML/SQL/PHP death rattle. With PHP5 you can use full-on object-oriented programming and still have the nifty benefits that scripting languages give you.

But I’m not going to leap to the pulpit, implore you to open your PHP docs to the Book of Rasmus, and lead you in worship of the language. You can’t design a “hypertext preprocessor” at the dawn of web programming and expect it to be perfect over the next decade. PHP has had flaws, and one could argue that there is a cultural flaw embedded in the language that leads to a lot of poorly-written code. By that I am talking about this sort of anything-goes, quick n’ dirty approach that allows the amateur to easily produce something workable with minimal effort. For an intriguing listen about the culture of a programming language (among other things), I highly recommend this podcast with Rails’ author DHH and Extreme Programmer Martin Fowler.

Yet when it all comes down to firing up emacs and writing web code, PHP provides me with the flexibility to write good software. I know the language intimately, I know when I can use PEAR to save some time, I know the php.ini settings, I know that Apache and mod_php are rock solid. In short, I have deep knowledge of a reliable programming tool and I can use it to rapidly develop maintainable, extensible web apps.

Of course, there comes a time when the familiarity with your current tool cannot compete with the benefits of a new tool. Is Ruby on Rails that white shore and far green country? Well, no. I’m not going to learn a new language, a new API, and – in the case of Rails – a custom implementation of a certain methodology running on a new application server, just so that I can have cool syntax and maybe fool around with closures. I don’t think that writing a quality MVC in PHP is going to be earth-shatteringly different from doing the same in Ruby – at least not enough so as to cover the activation energy of making the switch.

When I see people choking back their own vomit when “PHP” crosses their lips, I know they’re thinking about a different kind of PHP from the one I use. They’re thinking about raw SQL statements in nested loops, dumped with inconsistent indentation in a mass grave of <?php tags and HTML. That’s not the PHP I hack. I’ll keep my eyes on the programming scene with an open mind. If PHP begins to stagnate while Ruby forges ahead and puts together a strong mod_ruby, then I won’t need to be a shaman to read the cast of those bones. Until that time I will continue to dally with PHP, though it be strictly forbidden by the ancient laws of my tribe.

This entry was posted in Programming. Bookmark the permalink.

One Response to Loving PHP in a hostile world

  1. Pingback: Théoden’s Coding Tips » Blog Archive » How to check if a variable exists in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *