Click here to Skip to main content
15,908,013 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
AnswerRe: switch statement Pin
Tony Wesley17-Nov-07 4:26
Tony Wesley17-Nov-07 4:26 
GeneralRe: switch statement Pin
xenonysf21-Nov-07 2:05
xenonysf21-Nov-07 2:05 
GeneralRe: switch statement Pin
Tony Wesley21-Nov-07 6:50
Tony Wesley21-Nov-07 6:50 
GeneralRe: switch statement Pin
DavidNohejl16-Nov-07 13:39
DavidNohejl16-Nov-07 13:39 
GeneralRe: switch statement Pin
bsaksida17-Nov-07 4:12
bsaksida17-Nov-07 4:12 
GeneralRe: switch statement Pin
Tony Wesley17-Nov-07 4:31
Tony Wesley17-Nov-07 4:31 
GeneralRe: switch statement Pin
bsaksida17-Nov-07 4:16
bsaksida17-Nov-07 4:16 
GeneralRe: switch statement Pin
Tony Wesley17-Nov-07 4:45
Tony Wesley17-Nov-07 4:45 
bsaksida wrote:
why is there a switch inside switch

Well, it fits the logic. When the parser is starting a statement, the state is 1. Then it does a switch statement based on the first token.

The code all works, I'm just not happy with how complicated it is. I used SourceMonitor[^] to get a metric on the complexity.

Mike Swanson[^] suggests that <quote>Anything with a greater complexity than 10 or so is an excellent candidate for simplification and refactoring. Well, the code in question has a complexity number of 638 as measured by SourceMonitor.

You don't go from 638 to 10 in one step. So one of the things I did was to have a single exit with the error code at the top of the case statement. Or at least, I tried to. My logic error was a little embarrassing.

But an error like that is too good to keep to myself. I had to share it.
Generaltry-catch Oo [modified] Pin
Oshtri Deka16-Nov-07 0:19
professionalOshtri Deka16-Nov-07 0:19 
JokeRe: try-catch Oo Pin
Nemanja Trifunovic16-Nov-07 1:35
Nemanja Trifunovic16-Nov-07 1:35 
GeneralRe: try-catch Oo Pin
Nathan Holt at EMOM16-Nov-07 7:43
Nathan Holt at EMOM16-Nov-07 7:43 
GeneralRe: try-catch Oo Pin
Oshtri Deka16-Nov-07 11:14
professionalOshtri Deka16-Nov-07 11:14 
GeneralRe: try-catch Oo Pin
Ware@Work30-Nov-07 3:55
Ware@Work30-Nov-07 3:55 
GeneralRe: try-catch Oo Pin
Robert Royall16-Nov-07 9:45
Robert Royall16-Nov-07 9:45 
QuestionRe: try-catch Oo Pin
Chris Meech16-Nov-07 10:23
Chris Meech16-Nov-07 10:23 
AnswerRe: try-catch Oo Pin
Robert Royall16-Nov-07 12:38
Robert Royall16-Nov-07 12:38 
GeneralRe: try-catch Oo Pin
Oshtri Deka16-Nov-07 11:27
professionalOshtri Deka16-Nov-07 11:27 
GeneralRe: try-catch Oo Pin
Brady Kelly16-Nov-07 22:05
Brady Kelly16-Nov-07 22:05 
GeneralRe: try-catch Oo Pin
Chris Losinger17-Nov-07 12:40
professionalChris Losinger17-Nov-07 12:40 
GeneralRe: try-catch Oo Pin
StM0n21-Nov-07 0:26
StM0n21-Nov-07 0:26 
GeneralRe: try-catch Oo Pin
Mycroft Holmes29-Nov-07 16:37
professionalMycroft Holmes29-Nov-07 16:37 
GeneralRe: try-catch Oo Pin
Chris Losinger30-Nov-07 1:03
professionalChris Losinger30-Nov-07 1:03 
GeneralWhat does it do? Pin
bigbrownbeaver15-Nov-07 23:15
bigbrownbeaver15-Nov-07 23:15 
GeneralRe: What does it do? Pin
CPallini15-Nov-07 23:43
mveCPallini15-Nov-07 23:43 
GeneralRe: What does it do? Pin
Vasudevan Deepak Kumar16-Nov-07 0:00
Vasudevan Deepak Kumar16-Nov-07 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.