Thursday, January 24, 2008

PHP Sucks Balls.

This morning I read a rather hilarious article. It was posted on TheDailyWTF, and involved someone building a loop in a GUI that would artifically slow processing for the express purpose of being removable when the programming team needed an "accomplishment". Then, I read something even funnier. Some idiot was extolling the virtues of PHP, and suggested that he would point back to this article as his "sole defense" in future arguments. Well, for all of you who argue with this fine gentleman in the future, I'll do you a favor and win the argument for you right now. I've taken the liberty of copying the original article's (found here) points in italics, and refuted them sumarily.

Language Features

  • It's dynamically typed. This isn't a feature. It's a design decision made early on.
  • All arrays are associative (hashes) Which means that if you want to build an array, you have no easy way of guaranteeing that all indices will be numeric. Sounds like a recipe for trouble to me.
  • It's object oriented with a reflection API. Ruby, Java, and Python are object oriented. PHP is a procedural language with some stapled-on shit that they try to pass off as object orientation. Note that they still haven't implemented proper class and instance scoping, which makes objects in php just more typing, not more usable or functional.
  • It uses different operators for numeric addition (+) and string concatenation (.) This wouldn't be necessary if it had anything more than the most useless type checker in the universe.
  • It supports eval() and lambdas (somewhat) BASIC implemented eval() this well 30 years ago. Having a "dynamic" language with such a poor-performing eval() really should scare users of the langauge.
  • Can execute system commands and read from local and remote files (all one-liners) So can BASIC.
  • Supports coercing scalars into boolean decisions (means you can just do if($x) instead of if($x!=null && $x!=0 && $x!=false ... ) Coercing anything into boolean values is one of php's worst offenses, so it's a tad hilarious that this article mentions it as a "Feature". For instance, try evaluating 'if(1), if(0), if("1"), and if("0")'. See anything funny?
  • Usable in both web and command-line contexts Usable, but different. Just different enough to make a completely useless command line program.

Built-in Functionality

  • It comes with a vast array of built-in functions to do all sorts of common tasks. Here are a few off the top of my head:
    • Base 64 encoding and decoding And it lacks proper i18n support at the same time. Which would you rather have?
    • URL encoding and decoding My grandma could write a function to encode and decode URLs in about ten minutes. This is hardly worth noting.
    • HTML character encoding, decoding and tag stripping Again, I use a library my grandma wrote for this purpose.
    • SAX style XML parsing Yes. Computer languages can use SAX style parsers now. Is it really worth noting?
    • REGULAR EXPRESSIONS OMG ITS IN CAPS!!! Trivia quesiton: Can you find a language made in the last 15 years that doesn't support regular expressions?
    • Array sorting, custom sorting Sorting an array? Wow. That's tough shit. I had to get to CS 102 before I learned how to sort an array myself.
    • md5 and sha1 hashing So, they like, copied the pseudocode from wikipedia and compiled it?
  • It can natively connect to the most popular Database engines around. But it can't do so without resorting to using different functions for each database. (eg mysql_query() vs pg_query())
  • It comes prepackaged with graphics manipulation capabilities (GD) No. It knows how to access a GD installation on the same system.

Irrelevant complaints^H^H^H^H^H^H^H^H^H Just a few of the complaints this article refuses to^H^H^H^H^H CAN'T refute

Now, here are some common complaints about PHP, and why the don't matter:
  • I don't like PHP because it's not statically typed (like my beloved Java) News flash: static typing sucks - deal. Based on the logic this article demonstrates, the static vs dymanic debate is one it shouldn't touch with a ten-foot pole.
  • PHP doesn't have namespaces, so there can be naming collisions. Oh noes! Seriously, this is a theoretical objection, not a practical problem. Use a class dude - makes for a nice way to wrap your functions. This isn't theoretical in the least. See above, where querying to similar database engines use the same functions, BUT WITH DIFFERENT PREFIXES. PHP's lack of proper namespacing forces the language designers to do stupid shit like put "namespace_" in front of colliding function names, which makes the whole language even messier than it otherwise would be.
  • I hate globals Globals can save your life. Globals pierce through all the layers of code and get right to the heart of the matter. You say you don't like globals, so try to remember that the next time you grab a singleton from your static factory. Globals save the lives of programmers that don't know what the hell they're doing. Note to author: Reconsider what side of that elusive "circle" you're on.
  • PHP allows/promotes poor programming practices I call shenanigans on that one. PHP appeals to a broad audience, especially new coders, because it is ubiquitous. It's just as easy to write poor code in any other language (an Interface with exactly one Implementation anyone?) I'm not sure PHP allows it more than anything else, but it sure does market itself to the dumbest bunch of idiots that ever did type on a computer.
At least the author knows he's way behind. He's even kind enough to point out that "The curve is a circle", whatever that means. I tried to read the linked post, but it was long and sounded trite and angsty, but I interpreted it as this guy admitting that he sucks.

But! (there's always a "but", right?)

PHP does provide for the single greatest interview question every concocted. Now, when I'm interviewing candidates, the first question can be "Do you like PHP?". If they answer yes, I've just saved myself an hour.