Barry wrote:
> Jochem Maas schrieb:
> > I find a switch statement sometimes handy for creating a 'truth table'
>> like you describe (I sometimes find it easier to read and/or add 'if'
>> clauses):
>>
>> switch (true) {
>> case ($grandmaAge >= $tableAge):
>> case ($grandmaAge < $houseAge):
>> case ($grandmaAge == array_sum($grandKids)):
>> bakeCookie();
>> break;
>> default:
>> haveABeer();
>> watchFootball();
>> }
>>
>> functionally the above could just as well be an if statement - it's
>> pretty much
>> a question of personal preference.
>>
> Yeah true, it is better to view.
> Is it the same as the if i stated? (the grandma one)
the example I gave does this:
iif any of the case expressions (they can be arbitrary statements of which the
complexity is up to you - as long as they return a boolean) equates to true then
you bake a cookie OTHERWISE (the default ;-) you drink beer and watch footy -
which
given your german email address is rather apt right now :-P
I believe that is what you grandma example was aiming at
(I used artistic license with the beer and football part :-).
> it's one if but not multiple ones (if elseif elseif .. etc.)
>
> The problem still is it's not that "short" ;)
f*** 'short' the time taken to write a line is negligable compared to the
time taken to maintain, reread, change, enhance and/or adapt it.
try to think in terms of maintainability and readability - and of course
performance (the length of a line of code says very little, if anything,
about it's performance) - jmho.
>
> Barry
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php