[Baypiggies] Web Crawler/Backend Engineer - San Francisco, CA
keith at dartworks.biz
Thu Feb 4 06:12:17 CET 2010
=== On Wed, 02/03, Jeremy Fishman wrote: ===
> And on that note, I too think rich was a bit harsh on 'goto's. I
> definitively avoid them in general code, but occasionally they can
> serve the opposite purpose than that which their reputation predicts.
> A goto or two can clean up very specifically confusing code, such as
> when a several cases in a switch statement share different chunks of
> exit logic, but can't simple fall through. Sure, setting some flags
> and 'break'ing, or passing state to a helper function, would achieve
> the same thing, but it can clearly be cleaner and more understandable
> to 'goto label_foo' in the switch and then have some nice unindented
> cleanup labels before the function close.
But in a language/runtime that has exceptions, like Python, you don't
really need them. Just raise an exception where you would have the
"goto", and catch it where you would have the label. I think that is
even more readable than the goto.
-- Keith Dart
<keith at dartworks.biz>
More information about the Baypiggies