Re: PHP 4.0 Bug #8428 Updated: continue doesn't pass thru a switch statement

From: Date: Mon, 08 Jan 2001 18:17:26 +0000
Subject: Re: PHP 4.0 Bug #8428 Updated: continue doesn't pass thru a switch statement
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-43414@lists.php.net to get a copy of this message
On Mon, 8 Jan 2001, Stanislav Malyshev wrote: > Consider this syntax borrowed from Perl, not C :) In Perl it behaves in > quite different way, IIRC. If it was to operate identical to the Perl behavior, that'd be acceptiable to me. > Why is it _incorrect_? Just because C is always correct? I would argue that C is always correct by definition. It's a shitty arguement, since it leaves no room for actual debate. However, my claim is that when you've got an embedded base the size of C, then you're stuck supporting its behavior even when everyone knows it's wrong and agrees that it'd be better a different way. Now, I don't think that means you can't innovate beyond C, but just that the syntax shouldn't appear to be /like/ C. (Or, for that matter, like Perl or any other well-established language.) Syntax that identical in look, but different in behavior, can only lead to problems because people are bound to make assumptions that it'll act how they've learned it to act. I think that's natural and part of the reason why PHP's borrowed language constructs from C and Perl. If you're going to break from expected behavior, you should break hard. > BTW, I would always advise against using of evaluation order of _any_ > operator (except probably for logic shortcuts) because it's just not > readable (and not portable, as you just saw). Well, of course it's not readable, isn't the whole point of using ?: to create confusion? :) And, I've never been bitten by that ?: difference, nor do I think most anyone will. However, my point is that there is an established evaluation order that most languages observe. PHP's matches C's operator-for-operator, with this one exception. (Which, from what I remember, seems to be an honest mistake that nobody caught until it was too late.) After seeing that == and && and everything else works as they expect, I would think someone would jump to believing that ?: would be the same and why wouldn't portability be something worth perserving? Likewise, we probably wouldn't want to introduce something that looks like $foo =~ /bar/ that didn't operate like Perl's =~. In the end, I always use break and never continue in switch()es. However, it seems like a great place to introduce the possibility of a bug where one could be avoided. -adam -- / adam maccabee trachtenberg | it's what you think... \ \ adam@student.com | http://www.student.com /

« previous php.dev (#43414) next »