Jochem Maas schrieb:
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 :-).

Well not if "any". The have "all" to be true :)

Well i don't want the grandma to be not as old as the table and older than the house age and still baking a cookie.

Only if all cases stated are true, i want to bake a cookie :)

( Yeah the wm is up and running ;) )


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.

Surely true but writing short doesn't have to mean to write unreadable stuff.

IF ($grandma >= $tableage
        AND < $houseage
        AND== array_sum($grandkids)
        )
something like that (theoretically)


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.

Yeah it's not a performance issue its more like having to code a lot less than ATM "with" having the same readability as now.
Just shorter :)

Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

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

Reply via email to