Geeks and Gladiators
2000 years ago, it was Christians. When the Christians became the status quo, it was Jews and Muslims. Since reading recent blogs and after hanging out in a few chat rooms with the “techno-elite”, I’m thinking the newest group to be “thrown to the lions” are PHP developers.
Why do you ask? Well, just the other day I was hanging out in an obscure chatroom on irc. The channel was the geographically-nearest enthusiast channel for Ubuntu (and I am an Ubuntu enthusiast.) As I was trying to drum up some conversation (mostly because I was bored) I mentioned that I was a PHP developer to stunning silence. Okay?
The next night I log on again, after all, these are supposed to be people that are promoting Ubuntu and usually that encompasses the ability to be friendly and non-condescending. (Please, don’t get me wrong, I feel that, typically, the Ubuntu community is probably the best community for helping everyone fit in.) So, this time no chat is going on (as usual) and I sit idly by until I see some chatter (pretty standard and I was in a few other channels at the moment also.) One of the users (a very prolific and well-known contributor to Ubuntu in my relative geographic domain) was commenting that he had decided to use a certain application. However, he quipped, “Too bad it’s PHP.” Okay, that got my attention. There’s a conversation starter. I write, “Now I see why when I mentioned that I was a PHP developer, the room got really quiet.” Ha ha. I think I got a LOL or two. More silence. I then express how I’m always a little surprised that the django and rails crowd seem to feel some contempt for PHP. Longer silence. Finally, the other fellow posts something along the lines that PHP sucks. Mr. “Ubuntu Loyal” agrees with a two-worder meant more as a textual “high five.” I promptly agree that there is a lot of spaghetti code written by “newbies” in PHP, but that it’s not impossible to write good code using it. To that, I get a very condescending and elitist remark from the other fellow. It was along the lines of, “If you still use PHP, you are still a newbie.” What?! Well, that really ticked me off! I have over 9 years of Web development experience. This means, in my relatively short time in life, I have invested a large portion of my career devoted to writing web software. I consider myself a professional. Who does this elitist punk think he is calling me a “newbie!?” when I express my outrage, Ubuntu-man proceeds to tell me, very non-specifically, why PHP sucks. Basically, he tells me nothing new. He later back-pedals somewhat to convey that it’s the developers preference that really matters. I suppose I’m still a “newbie” by his estimation though. Anyway, I was a bit stunned by this irrational behavior. Was it warranted? Is PHP a truly awful language? Yes, and no.
PHP Complaints
PHP was originally envisioned as more of a templating engine. It began its humble roots in this manner just like many other world-changing web technologies. As more time went on, more feature requests were proposed, and more were implemented, until a “c-like” (block structured, procedural) language emerged. Now, I will take some liberty to make an assumption or two…
Because PHP grew as a collection of functions that are useful for Web development, higher-language programming syntax was not incorporated (Okay, assuming done. Moving on…) One of the chief complaints from the python and ruby-rousers is that PHP has no notion of name space (update. PHP 5.3 and 6.0 now have namespace syntax.) Name space is the practice of enveloping related functions and properties under a common container. The idea is that you can have a save() function in two entirely different name spaces because you can refer to each function with a name-space prefix first. For example, to save a database record, I could call a function named database.save(). That function would not be confused with the whale.save() function by the compiler because “database” and “whale” are different code containers. PHP haters complain that this forces PHP extension makers to create overly-long names and makes PHP less modular (because every single function is in scope.)
Another complaint is that variables are loosely typed (implicit.) That is to say, if I set a variable to “hello world”, PHP automatically assumes a string and converts that variable to a string type. if I set a variable to the numeral 1, PHP assumes I meant an integer…you get the idea. So what’s the problem? Well, without going overboard here, let’s say that my first variable is named $a (PHP variables begin with the dollar sign) and my second varible is named $b. When you write the expression: $a + $b, because one of the variables is of the string type: $a, PHP converts $a to an integer (0) and the result is just “1″. If I change $a to the literal number 2, PHP now makes an integer assumption and adds the two integers to make the result: 3. Critics of PHP complain that implicit typing creates more opportunities for bugs.
I’m just going to bunch together a few of the most common complaints that remain. PHP has no default caching mechanism. PHP uses anonymous arrays, PHP only has UNIX dates (1970-2038.) There are many other “band-wagon” and “brain-stormed” reasons. Many of which are deservedly so. Admittedly, It’s not a perfect language, but does it really hold you back so effectively as to engender contempt?
So yes, PHP has it’s limitations. Those of us who embrace PHP and use it on a daily basis are aware of PHP’s short-comings. But, just like any other language with “snags” (no programming language is perfect) we have learned to get around them to get the job done. I cannot say at this point that any of the issues complained about has created any significant roadblocks for me. In fact, a significant number of popular free open source web software out there is written in–you guessed it–PHP! If it’s so bad, why do these developers not switch to python or ruby? A few examples are drupal and wordpress (this blog is powered by drupal wordpress.) So, according to the “rail-heads” and “django-divas” we are led to believe that PHP programmers, such as the coders for drupal and wordpress are basically ignorant and coding with one brain-lobe tied behind their backs!
Irrational and unwarranted nonsense!
It’s almost to the point of paranoia. It reminds me of the Apple ads trying to convince you that everybody hates Vista. So, don’t use it or you’ll be sorry! As much as I would love a mac, I actually have Vista, and I like it! Developers with a few years of good PHP programming behind them actually like it as well!
Again, I promise that clean, easily-refactorable, and intuitive code can be, and is, written in PHP! For example, name space really isn’t the issue that the rhetoric suggests. I mean, really, how much harder is it to write mysql_connect() as opposed to mysql.connect()? (yes, it’d just be connect() if name space were declared but still not that big of an issue.) You can emulate name spaces by writing PHP’s code into your own objects which can be written very clear and concise just like any other high-level language. It all depends on the developer. Certainly not a “show stopper.” Furthermore, PHP 5 fixes a lot of the issues that have been criticized in the past. For example, I mentioned implicit types. PHP 5 supports type hinting. The difference is that you can choose to use it. If you have something simple you’re working on, you can choose not too. Some people actually consider implicit types as a convenience. I think it’s very convenient to be able to choose. In the several years I have been developing with PHP, rarely has implicit typing been an issue. Maybe the critics are just lazy programmers that need the compiler to babysit them. On that note, I recently read a post from a developer who stated that one of the many reason he hated PHP so bad was the lack of op caching. Even though it’s not built into the core of PHP, there is a free caching extension called APC. The manual gives you easy steps on how to install it. Again, you have the choice to use it or not. And speaking of extensions, the new PDO database abstraction extension is simply awesome!
I have heard a famous purveyor of a popular web framework rail on PHP citing that “his way” is more natural for web development. What he was really saying is that his framework that is built on another language is easier and faster than developing PHP. Unfortunately, he gives the impression that his preferred language is better for Web development than PHP. In reality, he is comparing a framework for rapid web development to a language. Not a fair comparison. While, I agree that the MVC model for web development works well, I think he is being disingenuous in his notion that his framework is the only way to accomplish this “natural way.” For example, there are numerous PHP frameworks that allow you to use the MVC model of development (my favorite is codeigniter.)
No Language is perfect. Even so, PHP is a great choice for beginners and pros alike.
I do admit that, because PHP doesn’t enforce a model for development (you can write procedural or object oriented code), programmers with little experience can write pretty awful and almost impossible-to-maintain code. But hey, you can write crappy code in any language!
PHP was designed to be a convenient language to learn and just knock stuff out (email forms, website authentication, etc.) And it performs this amazingly well! Web applications are more frequently simple than not. I have never felt held back by what I could or could not perform using PHP. I can also note, from a perspective of enterprise, PHP scales up just fine. The large variety of Web applications available that are written in PHP is proof. It all comes down to how smartly they were built. Facebook works just fine folks! Yes, it’s true, compiled code will always outperform code compiled on-the-fly, but python and ruby aren’t compiled either (besides, compiled code makes web development a pain in the backside IMHO.)
So yes, PHP may not be a perfect and high-level language. But then again, you don’t need a nail gun to build a bird house, a hammer works just fine. Don’t believe the hype! PHP works amazingly well for what it was meant to do. I wear a badge of pride that I call myself a PHP developer, so should you. Stand up for yourself!
2