Tags Perl

I happened to use a Good Goto (TM) today, which is funny, because just a week ago I posted in this journal my impressions of some chapter of "Code Complete" that spoke exactly about gotos that are allowable.

The goto points to special condition code. Something like this -

sub foo
{
  ...
  goto undefined_behavior if (something_bad1)
  ...
  ...
  goto undefined_behavior if (something_bad2)
  ...
  ... etc
  ...

  return

undefined_behavior
  do stuff...
  return
}

Some of the conditions depend on earlier ones' being good, so trying to make it w/o a goto would be a bloody mess of if..elsif . With goto, the code looks clean and easy to understand.

Cool !


Comments

comments powered by Disqus