4 ms·
There are ways to use goto effectively... in fact, the other day I was working with an awkwardly nested try/catch that would have read much clearer as a goto (a
by pak 17y ago
There are ways to use goto effectively... in fact, the other day I was working with an awkwardly nested try/catch that would have read much clearer as a goto (and more efficiently; an empty Exception was being used to trigger the catch).
I've seen this problem "solved" with a do while false and a break, but isn't that even hackier and less expressive?
At this point I think goto-phobia is well understood enough that adding it for occasional use wouldn't ruin the language.
- aphyr 17y agoRuby distinguishes between begin/rescue (analogous to Java's try/catch) and throw/catch. I never understood it until discovering that throw/catch is perfect for dealing with nested cases where rescue or break fail. Also, it works through function calls and isn't interpreted as an error, which makes it great for cases like Ramaze's redirect or render calls; unlike in Rails, they interrupt execution immediately.