I just want to thank you for your great editorial in the February issue of Overload ("'They' Have Their Reasons"). As you write: "If you can find and talk to them you will find that "they" are normal human beings trying to achieve reasonable goals in reasonable ways." Deep inside, I know this to be true, but it's still good to be reminded of it, especially if you deal with someone who appears "unreasonable". They are probably reasonable, from their perspective.
What inspired me to write this is that I've lately been discussing with some people in the PHP community, and "they" don't appear to appreciate the value of higher abstractions (preferring a "simple language", even though this may lead to complex or verbose code). Or even stronger type-checking, I may add. In C/C++/Java, we may write:
void f(int a, string b, vector c)
and we know it takes an int, string and vector, no more, nor less, and returns nothing. In PHP, with the following:
function f($a, $b, $c)
we know hardly anything: We know that it takes (at least) three arguments - but it may take more - and we know nothing about their type, and any return type (and it may return different types, or nothing at all, depending on its run-time path through the function... All variables in PHP are like variants - they can take on any type). I can't for the life of me understand how someone finds writing code like this more "productive" and "easier". Myself, I've spent way too much time chasing stupid type-related bugs in PHP, that could have trivially been checked by the compiler/runtime. Flexibility to do what? Make type-related errors? Sorry, if I really want to do that, I want to say so explicitly - by overriding the type-system with a cast.
My company makes web applications for other companies, and we're using PHP, and I've been using it professionally for a couple of years, so it's not like I'm a PHP beginner, but still the above baffles me. I like not having to wait for compilation with PHP, but if I could choose stronger type-checking, my answer would be YES. The kind of absent type-checking above tends to encourage sloppy coding, and you have to explicitly check for types inside the function, if you want to do so (it's similar to having to explicitly check for return codes, which is often not done... At least PHP 5 does have exceptions). You still can't enforce a certain return type, though. Really, if I wanted a particular parameter to be a "variant", I'd specify that (and if the types it could have were known, I'd enumerate them, and if not, use something like boost::any). It adds information and explicitness to the code, and should make it easier to understand. Yet, it appears the majority of PHP developers don't want it (from what I've read on various mailing lists and newsgroups). Why? Have you got any idea?
Overload Journal #66 - Apr 2005 + Letters to the Editor
|Browse in :||
All > Journal Columns > LettersEditor (127)
Any of these categories - All of these categories