waikay.net

rambles of an avid procrastinator
"Why do today what you can do tomorrow?"

Archive for February 4th, 2006

Happiness is

Saturday, 4 February 2006, 3:58 am, me

Happiness isn’t happiness without a violin playing goat.

Problem is, there is no violin playing goat.

Currently: sad Sad

Filed under: rambles

My ‘l33t’ Code

Saturday, 4 February 2006, 1:55 am, me

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?

Filed under: jargon

Creative Commons License
Except stated otherwise, content of this site is
licensed under a Creative Commons License.