Click here to Skip to main content
16,011,538 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.

 
GeneralRe: Do it only once please Pin
CPallini18-Nov-07 22:50
mveCPallini18-Nov-07 22:50 
GeneralRe: Do it only once please Pin
Tony Wesley20-Nov-07 11:23
Tony Wesley20-Nov-07 11:23 
GeneralRe: Do it only once please Pin
chmod222220-Nov-07 20:03
chmod222220-Nov-07 20:03 
GeneralRe: Do it only once please Pin
Tony Wesley21-Nov-07 4:49
Tony Wesley21-Nov-07 4:49 
GeneralRe: Do it only once please Pin
leppie19-Nov-07 1:43
leppie19-Nov-07 1:43 
GeneralRe: Do it only once please Pin
CurtD23-Nov-07 13:09
CurtD23-Nov-07 13:09 
GeneralRe: Do it only once please Pin
Tony Wesley23-Nov-07 19:40
Tony Wesley23-Nov-07 19:40 
GeneralRe: Do it only once please [modified] Pin
CurtD15-Dec-07 17:53
CurtD15-Dec-07 17:53 
Tony Wesley wrote:
The goto doesn't figure into that. Just above it in the thread is another snippet of my code that doesn't use a goto.

Same issue. What happens to the code after the while loop when an exception is thrown? It doesn't get executed.

Once could argue that the problem is with exception. As I pointed out elsewhere, Joel Spolsky argues that exceptions [...] create an abrupt jump from one point of code to another. In fact they are significantly worse than goto's: (emphasis added)

I don't quite agree with Joel. But there was a time, when I was debugging an app that another programmer had written, that I understood that completely. It was spaghetti exception handling. I never knew where I had come from.

I'm not saying you shouldn't use exceptions. But they can be abused as badly as gotos.


I'm talking about the case where coders like to put a block of cleanup code at the bottom of a method and "goto" it when something goes wrong or fall into it in a non-error situation. If you are depending on blocks of cleanup code, an exception will bypass it completely. This worked back in C, but not in OO design.

That's why I use objects that clean themselves up when destroyed -- automatically. I am far too lazy to try to figure out every possible error situation, catch exceptions from anything that might throw them, and ensure that there is an appropriate goto.

I disagree completely with Joel Spolsky. He suggests using return codes instead of exceptions. Return codes and exceptions are completely different things. Exceptions are not meant to be return codes. They are "exceptional" situations where usually the app cannot continue. And exceptions have the major advantage of unwinding the stack, which he fails to mention. They are not "an abrupt jump from one point of code to another."

It seems like OO programming has really failed to catch on with a lot of developers.
modified on Sunday, December 16, 2007 12:10:46 AM

GeneralRe: Do it only once please Pin
PIEBALDconsult16-Nov-07 16:06
mvePIEBALDconsult16-Nov-07 16:06 
GeneralRe: Do it only once please Pin
Tony Wesley17-Nov-07 4:32
Tony Wesley17-Nov-07 4:32 
GeneralRe: Do it only once please Pin
Chris Losinger17-Nov-07 12:31
professionalChris Losinger17-Nov-07 12:31 
GeneralRe: Do it only once please Pin
PIEBALDconsult16-Nov-07 12:16
mvePIEBALDconsult16-Nov-07 12:16 
GeneralRe: Do it only once please Pin
Marc Clifton18-Nov-07 14:03
mvaMarc Clifton18-Nov-07 14:03 
JokeRe: Do it only once please Pin
codemunkeh29-Nov-07 12:34
codemunkeh29-Nov-07 12:34 
GeneralRe: Do it only once please Pin
Xiangyang Liu 刘向阳19-Nov-07 20:47
Xiangyang Liu 刘向阳19-Nov-07 20:47 
GeneralRe: Do it only once please Pin
Dalek Dave20-Nov-07 3:58
professionalDalek Dave20-Nov-07 3:58 
GeneralRe: Do it only once please Pin
Secrets20-Nov-07 23:50
Secrets20-Nov-07 23:50 
GeneralRe: Do it only once please Pin
KarstenK21-Nov-07 1:33
mveKarstenK21-Nov-07 1:33 
GeneralRe: Do it only once please Pin
Michael Davey 124-Nov-07 20:43
Michael Davey 124-Nov-07 20:43 
GeneralRe: Do it only once please Pin
Xagyg29-Nov-07 4:03
Xagyg29-Nov-07 4:03 
Generalswitch statement Pin
Tony Wesley16-Nov-07 6:33
Tony Wesley16-Nov-07 6:33 
GeneralRe: switch statement Pin
Oshtri Deka16-Nov-07 11:33
professionalOshtri Deka16-Nov-07 11:33 
GeneralRe: switch statement Pin
Tony Wesley16-Nov-07 11:38
Tony Wesley16-Nov-07 11:38 
GeneralRe: switch statement Pin
Oshtri Deka16-Nov-07 15:02
professionalOshtri Deka16-Nov-07 15:02 
AnswerRe: switch statement Pin
Tony Wesley17-Nov-07 4:26
Tony Wesley17-Nov-07 4:26 

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.