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

Men Explain Why Women’s Yoga Pants Should Be Banned In Public

Read more… Source link

Why It’s Never A Good Idea To Meet Your Heroes

“This was at my elementary school in Japan in 1991. A bunch…

I Took An “Alternative” Senior Photo

“My senior picture, 1984.” (via source) The post Holy Smokes appeared first…

“Person Of The Year” Taylor Swift Subtly Labels Kim Kardashian And Kanye West “Trash”

Taylor Swift, who has just been named TIME Magazine’s Person of the…