Click here to Skip to main content
15,907,001 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: 16 layers of ifs, Who dare challenge this? Pin
PIEBALDconsult20-Jan-09 6:23
mvePIEBALDconsult20-Jan-09 6:23 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Chris Maunder20-Jan-09 15:10
cofounderChris Maunder20-Jan-09 15:10 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Luc Pattyn20-Jan-09 15:49
sitebuilderLuc Pattyn20-Jan-09 15:49 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
PIEBALDconsult20-Jan-09 16:35
mvePIEBALDconsult20-Jan-09 16:35 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Chris Maunder21-Jan-09 2:08
cofounderChris Maunder21-Jan-09 2:08 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Phil J Pearson21-Jan-09 2:03
Phil J Pearson21-Jan-09 2:03 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Chris Maunder21-Jan-09 2:08
cofounderChris Maunder21-Jan-09 2:08 
GeneralGOTOs Pin
supercat921-Jan-09 6:37
supercat921-Jan-09 6:37 
Sorry Chris, but that second option is just a <hushed_tones>goto that avoids using the letters 'g' or 't'.

The reason GOTO has gotten a bad rap is that it has historically been used without any concept of structured control-flow. Programs are generally easiest to understand if they can be subdivided into nested blocks, such that there are few jumps across block boundaries, and all inter-block jumps are of a few specific forms (e.g. jumping to the start or end of an enclosing block). Consider:
  if (condition) goto TRUE_CASE;
FALSE_CASE:
    do_false_stuff();
    goto END_IF;
TRUE_FASE:
    do_true_stuff();
END_IF:

Not quite as nice as using the C block constructs, but not particularly nasty. On the other hand, prior to the invention of structured programming, such code would often have been written as:
  if (condition) goto TRUE_CASE;
  do_false_stuff;
END_IF:

  .. somewhere else in the code ..
TRUE_CASE:
  do_true_stuff();
  goto END_IF;

The code for the true case would often be placed rather arbitrarily. In assembly code written for some machines, it might be placed before the start of the routine which used it, so as to allow an efficient short-displacement branch. Trying to follow code whose physical arrangement bears no relation to its logical flow is, of course, difficult. The problem, though, isn't the use of GOTO per se but rather the use of control flow that doesn't follow any logical structure.

(nb: I do sometimes write assembly code which is more like the latter than the former, particularly in cases where the 'if' case occurs far less frequently than the 'else' case, and the performance impact of adding an extra branch to the 'else' case would be significant and unacceptable. I don't like such code, but sometimes it is necessary).
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
GibbleCH22-Jan-09 11:21
GibbleCH22-Jan-09 11:21 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
supercat922-Jan-09 13:14
supercat922-Jan-09 13:14 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
ClementsDan4-Feb-09 17:21
ClementsDan4-Feb-09 17:21 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Mohammad Dayyan21-Jan-09 8:58
Mohammad Dayyan21-Jan-09 8:58 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
PIEBALDconsult21-Jan-09 9:27
mvePIEBALDconsult21-Jan-09 9:27 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Mohammad Dayyan21-Jan-09 9:40
Mohammad Dayyan21-Jan-09 9:40 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Dan Neely21-Jan-09 9:35
Dan Neely21-Jan-09 9:35 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
PIEBALDconsult21-Jan-09 12:21
mvePIEBALDconsult21-Jan-09 12:21 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Dan Neely22-Jan-09 2:12
Dan Neely22-Jan-09 2:12 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
sucram28-Jan-09 1:38
sucram28-Jan-09 1:38 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
Geoff Field2-Feb-09 15:22
Geoff Field2-Feb-09 15:22 
GeneralRe: 16 layers of ifs, Who dare challenge this? Pin
KarstenK3-Feb-09 21:02
mveKarstenK3-Feb-09 21:02 
GeneralRe: 16 layers of ifs, Who dare challenge this? [modified] Pin
Megidolaon23-Feb-09 23:03
Megidolaon23-Feb-09 23:03 
RantFTW? Pin
Rotted Frog15-Jan-09 8:02
Rotted Frog15-Jan-09 8:02 
GeneralRe: FTW? Pin
PIEBALDconsult15-Jan-09 8:26
mvePIEBALDconsult15-Jan-09 8:26 
GeneralRe: FTW? Pin
geegeegeegee15-Jan-09 17:50
geegeegeegee15-Jan-09 17:50 
GeneralRe: FTW? Pin
Chris Maunder15-Jan-09 19:11
cofounderChris Maunder15-Jan-09 19:11 

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.