Structured exception handling is a powerful way to describe how your program reacts to error conditions. But it’s not available in a language like C, and thus C programmers have come up with a variety of ways to propogate errors. Frequently, functions simply return error codes. Some error handling practices use the dreaded goto to jump to the error handler.

Or, they do what “Maple Syrup“‘s predecessor did for all of their error handling code:

do {
  
  if (failureCondition)
    break;
  return TRUE;
} while (0);

Now, if you check the comments on this article about an hour or two after posting, you’ll see some lovely essays describing why this particular construct is the best possible option to use in certain cases, and that it’s definitely not a WTF and it shouldn’t be posted on this site.

But in the meantime: just look at it. At its core, it reinvents the goto by exploiting the break keyword inside of a loop that will never repeat.

It works, despite the syntactical noise it adds to the code. Is it how any of these constructs should be used? No, but in the words of William Gibson: the street finds its own uses for things.

Remy Porter

Source link

You May Also Like

Punk Santa Is Coming To Town Santa – People Of Walmart

The post Punk Santa Is Coming To Town Santa appeared first on…

r/funny – Cat confused by the sound

This is a friendly reminder to read our rules. Memes, social media,…

Liberal Democrats poking their noses in again

Although you barely remember their names or faces, Liberal Democrats have been…

Welcome to the Deep End (25 Photos)

Hendy Source link