Click here to Skip to main content
15,917,645 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
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 
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 
If there were nothing other than functions called in sequence, then one could use:
{
  if (operation1())
    return -1;
  else if (operation2())
    return -2;
  else if (operation3())
    return -3;
  return 0; /* Success! */
}
which is I think nicer than using the flag. The place the flag is helpful is when there are things going on other than the simple operations, e.g.
if (!error)
{
  setup_for_operation2();
  error = operation2();
}
I'm not a particular fan of using the && operator; if one wants to put each operation on one line, one could code it as
if (!error) error = operation3();
which is clearer than the && version, is more versatile when zero is error case (the error flag will hold the particular error code returned, instead of having to hold zero or one), and may yield more efficient code if 0 is error and 1 is success (a statement like ok = ok && operation3(); is likely to perform a redundant write to ok when it's equal to zero.
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 
GeneralRe: FTW? Pin
Rotted Frog16-Jan-09 3:21
Rotted Frog16-Jan-09 3:21 
GeneralRe: FTW? [modified] Pin
cybertone16-Jan-09 19:00
cybertone16-Jan-09 19: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.