PHP: Just for Newbies?

3

Posted on : 03-10-2008 | By : Brett | In : PHP, Programming, Technology

Geeks and Gladiators

Two-thousand years ago, it was conquered soldiers and Christians. Since recently reading some 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!

It’s convincingly apparent if you search the “blogosphere” that many “techies” think that the phrase PHP programmer is an oxymoron. If you use PHP does that really earn you the despised title of newbie?

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-pretentious” and the “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!

Comments

I look forward to reading other articles you have. Which is Informative and creative.

Thanks!

I came across your article after settling a bet on how many results google would return with “too bad it’s php” or “too bad it’s in php.” This was after a discussion about whether to simply discount any php project without further research as we look for a tool to meet our needs.

FWIW, I think the point about the possibility of writing clean, consistent php code demonstrates the issue. There’s no argument over whether Python or Java developers can write clean code, because most Python and Java projects are relatively consistent. Java in particular is unique homogeneous, so much so that almost all Java projects actually adhere to the same coding standards, from camelCase to package organization.

With PHP, some projects are clean, others are not. Many of us old-timers are still suffering PTSD from “magic” features from early iterations of PHP, such as bugs resulting from “smart quoting” in the 90s (when a run-time system configuration flag affected how variables are represented). Another simple fact is that most of us who suffered through PHP had to suffer through code that someone else wrote, that broke. The clean projects that avoid PHP’s shortcomings we don’t see, because they don’t break.

There are practical reasons why mysql.connect is vastly superior to mysql_connect — namely that you can specify a backend engine in one place, and use it agnostically throughout the code. The fact that an API exists in PHP to do that isn’t really the point. It’s the bad taste left in your mouth when you see how it got started.

There are some very high quality projects written in PHP. Maybe its informal growth pattern discourages over-engineering. Drupal, after all, is far better than Zope, even though Zope (in all its complexity) is supposedly very powerful, even though no one can figure out why.

Ultimately what does matter is the end result, the fun you have writing code, and what makes you happy. My fellow Python (and Java) geeks think I’m crazy because I enjoy Javascript. It isn’t that I think Javascript is well-designed (it isn’t), it’s that I like what I can do with it. I think the same applies to PHP. People do amazing things with PHP, and that’s what matters.

Greetings Ken,

Thanks for taking the time to read my little rant from so long ago.

You make some very good points. I make no argument against the notion that PHP promotes bad coding due to a more-than-typical lack of Homogeneity. In fact, sometimes I think if I didn’t have code completion in my IDE, I’d never get anything done. :) My argument wasn’t so much for promoting PHP on equal standing with better languages such as python, ruby, perl (yes, perl) , etc. My contention was that it’s perfectly adequate for Web applications because you often do not need to write some giant project for the Web. It’s generally available everywhere and makes a lot of sense because you have a better chance that your designer/programmer can crank out a little code from time-to-time. That, and you shouldn’t have to feel ashamed that you use it! :) However, I understand that you are trying to better explain why PHP contempt exists in general. Again, good points.

In recent years, I’ve gotten my hands on python for several projects. I really like how I can almost write it without code completion (among other things I won’t mention right now.) In fact, I really considered doing a larger project that I am currently working on in django. However, I have yet to do a Web project in django and decided I better wait to ride that learning curve with some less significant project. Before this post, I had coded several projects using C#. Oddly, I’ve never laid hands on Java for any real project. Could this be that barrier to entry that keeps us newbies tied to PHP? That, or I’m just lazy. :)

Yes, an inferior language can make you less productive (and cause headaches for future developers.) I’ve seen my share of bad PHP code that made me want to hurt certain persons (mostly oscommerce developers.) When I first started at my company about 10 years ago, I cut my teeth on legacy ASP. Unfortunately, I’m still maintaining several projects/snippets after all these years. Now that is a truly limiting language!

I also enjoy writing javascript!

Cheers.

Post a comment