PHP Musings


Ran into an interesting, but thorough, rant the other day – PHP: A Fractal of Bad Design.  The part that grabbed me the most was the analogy at the beginning, which was all too perfect:

I can’t even say what’s wrong with PHP, because— okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there.

You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes.

You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.

You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever.

And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools.

Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.

That’s what’s wrong with PHP.

That sums up my feelings fairly completely – there’s nothing that doesn’t actually get the job done; that, is, everything works; but it’s just all quirky and strange and inconsistent.  Further, a lot of the issues are mitigated with a good framework – I prefer Yii, myself, but I hear good things about CodeIgniter as well.

Still, the rant got me thinking.  Going through the full list, there seems to me that some of these could be fixed without too much breakage.   That is, that they’re strange behaviour in corner cases that you wouldn’t really do anyway, so what harm would come from changing the behaviour?

Others are more interesting in terms of breakage – function renaming for consistency, for example, or changing argument order in certain functions. Still, I wonder if there’s enough demand out there to create a “cleaner” version of PHP that fixes some of the glitches, even at the expense of backward compatibility.   How much could be done without breaking backward compatibility except in corner cases?

+ more

Accurate Timing

Accurate Timing

In many tasks we need to do something at given intervals of time. The most obvious ways may not give you the best results. Time? Meh. The most basic tasks that don't have what you might call CPU-scale time requirements can be handled with the usual language and...

read more