Code Elegance

Are we sure that goto is dead?

Last week, during a code review I found this code (I cut some lines to keep the post short)

 

// [Cut]
case USER_AGENT:
     // [Cut]...various code....
     goto default; //we want it to be added to serverVariables
case CONTENT_TYPE:
     // [Cut]...more code (with some "if")
     goto default; //we want it to be added to serverVariables
 case USER_LANGUAGE:
     ParseUserLanguage(variableValue);
     break;
 default:
     ServerVariables.Add(variableName, variableValue);
     break;
// [Cut]...continue...

No words.

 

Technorati Tags: ,,
Posted in Emanuele DelBono | 3 comments

3 Comments so far

  1. Derick Bailey March 12th, 2009 23:01

    looks like it’s time to introduce some design patterns and better OO principles to your team! do some training and then challenge the team (everyone on the team) to come up with some alternative solutions to this chunk-o-code.

  2. emanuele March 25th, 2009 09:06

    Yep! I absolutely will try it. If someone wrote that code means that the Code principles are not clear.

  3. Jeremy June 2nd, 2009 14:53

    A computer scientist is someone who, when told to ‘Go to Hell’, sees the ‘go to’, rather than the destination, as harmful.

Leave a reply

Spam Protection by WP-SpamFree