metautonomo.us

Confounding URL typists since 2007.

PHP: A Bridge Too Many?

Posted by Ernie on August 20, 2008 at 1:39 pm

Development language preferences are funny things. I’m well aware of the benefits that come from being familiar with many languages, not least of which is the perspective needed to discern the right tool for each job. As they say, when the only tool you have is a hammer, everything looks like a nail. I’ve had exposure (in varying degrees) to a fair number of programming languages in my time: BASIC, Pascal, Ada, C, Bourne Shell, Perl, Python, PHP, Java, Javascript, VB, and Ruby among them, so I feel as though I do have some general ideas about the kinds of features I look for in a language.

All that being said, there are some tools that I can’t help but wonder about. PHP is one of them.

Hold it right there.

I am aware of the irony in what I’m saying, because the very software that powers this weblog is written in PHP, and it’s a fine piece of software, indeed. So let me be clear:

  • I’m not saying great PHP software isn’t written every day.
  • I’m not saying PHP doesn’t drive some of the most awesome sites on the web.
  • Most importantly, I’m not saying that PHP developers are bad developers.

If you had already run to the shed in your backyard to grab your pitchforks and torches, please return them to their proper resting place.

What I am saying is that for me, what constitutes a "good" programming language has nothing to do with how many companies are using it, nor how many great applications are written in it. Sure, those are awesome reasons to check out a language, because usually, where there’s smoke, there’s fire. That’s led me to look at PHP again and again in the past 10 years or so, almost every time I read an article about how "mature" PHP has become. But I keep walking away wondering what all the fuss is about.

Pittsburgh: Hypertext Preprocessor?

Quick aside: I lived nearly 25 years near Pittsburgh, Pennsylvania before I moved to Louisville. Pittsburgh is an awesome city. Great skyline, lots to do, and wonderful people. No matter how long I live elsewhere, it’ll always feel like my hometown.

But it has bridges.
Lots of bridges.
446 bridges, to be exact.
More bridges than Venice, Italy.

I used to joke that it was like we built a small town at the center of three rivers when rivers were a primary means of transporting goods, then were taken completely by surprise when it grew. Bridges just kept popping up everywhere, and you can’t help but think that if someone − anyone − would have just taken a step back and looked at the big picture (you know, somewhere around bridge #250?) that there would be a lot fewer bridges, and people would still get around just fine.

I only mention this because that’s kind of how I think of PHP. A great community, with a ton of nice people who have nothing but the best of intentions. Yet, when I compare PHP to something like Perl or Ruby, I always come away feeling like PHP just kept building new bridges as it grew, without taking a step back and looking at the big picture.

Madness? This… is… the global namespace!!

Consider this: A typical PHP installation today has over 3,000 functions in its global namespace, and there isn’t even a clear naming convention to be found among them. Have a look at the "Quick Reference". Now, poking through the list of string functions, here are a few examples of what I’m talking about:

  • addslashes – Quote string with slashes
  • addcslashes – Quote string with slashes in a C style
  • stripslashes – Un-quotes a quoted string
  • stripcslashes – Un-quote string quoted with addcslashes
  • stripos – Find position of first occurrence of a case-insensitive string
  • strpos – Find position of first occurrence of a string
  • strripos – Find position of last occurrence of a case-insensitive string in a string
  • strrpos – Find position of last occurrence of a char in a string
  • parse_str – Parses the string into variables
  • strtok – Tokenize string
  • str_split – Convert a string to an array
  • similar_text – Calculate the similarity between two strings

You get the idea. A global namespace with over 3,000 functions would be bad enough if the function names were chosen with some predictable pattern, but I dare you to find a method to the madness here. When I compare this the the simple elegance in Ruby, Python, or Perl (yes, Perl!) I’m just baffled by the design decisions (if they can be called that) made by the PHP team.

Let’s burn some bridges.

It’s really frustrating to me as a developer, because PHP is one of those languages which I truly feel does try to address a problem space I work in regularly. It just feels so clunky that I can’t make myself love it the way I do other languages. I can’t imagine that I’m the only one who feels this way, even including those in the PHP community.

At what point will the community stand up and collectively make the call to stop building new bridges before they’re sure that they’re building in the right spot? Maybe even take a step back decide there are some bridges that deserve to be burned, as well?

Filed under Blog
Tagged as ,
You can leave a comment, or trackback from your own site.