[ Content | View menu ]

My Own Biases

Mark Mzyk | January 7, 2008

If you read my blog with any regularity, you know that I’ve developed a regular series called PHP Insanity.  Three entries so far and counting.

Raganwald’s latest post made me question the validity of this series.  Was I guilty of claiming that PHP violated the principle of least surprise, simple because I am not intimately familiar with the language?

It certainly cannot be claimed that PHP operates like other languages.  It has plenty of it’s own quirks, and plenty of those quirks have caught me by surprise.

Yet I don’t think I’m guilty of falsely condemning PHP.  It deserves every proclamation of damnation against it I can give.  Well, almost all.  I’m not infallible from time to time.

Why am I not guilty?  PHP strives on many levels to operate like other languages, especially since it is adding object oriented features.  It reasons that in trying to be like other languages, PHP should therefore operate like them in most cases, except in recognized exceptions where PHP feels that operating in a different way is of value.

If you can tell me what those recognized exceptions are, please let me know.  PHP appears to me to go off in its own direction at random, my favorite example of which being the choice to have intval return zero, a valid integer, on failure.

PHP’s problem is that it consistently violates the principle of least surprise.  PHP mimics other languages, making me feel I’m in familiar territory, then behind the scenes it changes the rules and makes me feel like the fool.

Raganwald talks about structures that:

… require study to understand. But once understood, they make code easier to read thereafter.

PHP doesn’t do this.  PHP presents structures I should already understand, then makes me study them, because in PHP those structures violate my understanding.

It all boils down to one thing.  It’s one thing PHP is very guilty of and would do well to fix: Bad Design.

Filed in: General,Languages.