6 ms·
It's worth noting that the coding climate has changed considerably since 1987. Modern goto-less languages, such as Java, include break and continue statements t
by jcranmer 11y ago
It's worth noting that the coding climate has changed considerably since 1987. Modern goto-less languages, such as Java, include break and continue statements that can target any enclosing block; many of the example programs that people suggest using gotos for end up basically using these forms. It's worth pointing out that these multi-level break/continue statements allow you to build any reducible control flow graph (that is, the only thing you cannot do is construct a loop which has two entry points; incidentally, these constructs are also the best way to ensure that the optimizer gives up).
Optimizers have also gotten better over the years--it would be fairly easy to transform the idiomatic find-loop pattern based on flags to the one that uses the goto. There's also been a shift to using basic block-based optimizers, which means that the optimizer sees a loop statement and something built entirely of gotos as completely identical anyways.
So, in the end, the goto debate is moot: there's no real difference in performance either way these days, and we've renamed the goto instruction to break which sidesteps most of the puritanical section of the debate.
- sklogic 11y agoThere is a still a noticeable difference in performance of a `goto`-based FSM implementation and a switch-in-a-loop one. And there is a huge performance difference between a computed `goto` implementation of a VM vs. a switch-based one. Break is not a substitute for any of this use cases.
- 0x07c0 11y agoIn my current project I use both. Direct coded lexer and a vm using gnu-c &&label.
- nickpsecurity 11y agoCouldn't one just macro an implementation of such things that use goto underneath?
- sklogic 11y agoOf course. But only if goto was not removed from the underlying language.
- nickpsecurity 11y agoI wonder if anyone has done a safe form of goto that does static analysis or something to see if the jump is safe. My only experience was making error handling easier to understand.
- sklogic 11y agoIt is rather trivial to check if a control flow is reducible (can be a platform requirement, e.g., OpenCL spec demands this). But it is unlikely that you can do too much of a static analysis with a computed goto, and the latter is the most interesting and the most useful form.