Re: Re: Switch - Case Statement Questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19 Nov 2012, at 19:35, Tim Streater <tim@xxxxxxxxxxxxxxxx> wrote:

> On 18 Nov 2012 at 14:44, Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx> wrote: 
> 
>>>>>> 2. Using Switch {ALWAYS FIRST CASE!!!}
>>>>>> 
>>>>>> //        $boxes = 1;
>>>>>> //        switch ($count) {
>>>>>> //            case ($count > 14):
>>>>>> //                $boxes = 3;
>>>>>> //                break;
>>>>>> //            case ($count > 7 && $count <= 14):
>>>>>> //                $boxes = 2;
>>>>>> //                break;
>>>>>> //            case ($count <= 7):
>>>>>> //            default :
>>>>>> //                $boxes = 1;
>>>>>> //                break;
>>>>>> //        }
> 
> 
>> To answer Iñigo's comment - the OP's version is very much like an
>> If-ElseIF structure, and nothing like a Switch.
> 
> Just so. Perhaps those who are not grasping the point could re-read their copy of "The Elements of Programming Style" by Kernighan and Plauger where this sort of issue is covered.

And of course, nothing is allowed to have changed since 1978! Using a switch in that manner is normal for me. Should I change my style simply because you don't agree with it? If so, why don't you change your style because I don't agree with that? Code is art; there is no "right" way to do it. Can code be shown to be more efficient, elegant, faster, cleaner? Yes. Right or wrong? No.

> See, it's all about expectations. When I worked at SLAC, there was a wise guy there who had removed the catalytic converter from his Scirocco and who though it clever to race up 280 from San Jose to SLAC at 100mph, sometimes slipstreaming behind another idiot doing the same. If I look in my rear-view mirror, I expect those I can see to be doing 70mph tops (that's what a lot of people did 30 years ago on 280), not 100, and to make judgements accordingly. Equally, I have certain expectations when I see a switch statement; it trying hard to look like if-elseif-etc is not one of them.

Why is it their fault for doing 100mph and not yours for assuming they're only doing 70mph? I'm not saying they're right to be doing 100mph, but I'm definitely saying you're wrong for assuming they're only doing 70mph.

Assumptions are the mother of all f*** ups.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux