Archive for February 4th, 2006
Happiness is
Happiness isn’t happiness without a violin playing goat.
Problem is, there is no violin playing goat.
My ‘l33t’ Code
Ok I don’t think anybody would be attempting to solve the little quiz I had so I’m just going to post my solution here.
switch ($usertype)
{
case "Administrator" :
if ($priv == "Administrator") return true;
case "Manager" :
if ($priv == "Manager") return true;
case "Registered" :
if ($priv == "Registered") return true;
case "Anonymous" :
if ($priv == "Anonymous") return true;
}
return false;
In case you’re wondering, this technique makes use of the “fall-through” condition of swtich statements, which is common in languages like PHP, Java and C. Note the missing break statement.
On efficency wise, switch statements are syntactic sugar for a couple of if statements and gotos (jumps), thus I would say it’s quite efficient. Readabiliy wise, it’s very clear to me. Easy to modify and understand I hope.
Comments?







