4 ms·
The reason why Linus Torvalds and others prefer to handle errors using goto is that it avoids the main branch of the code receiving an additional indentation, a
by chalst 15y ago
The reason why Linus Torvalds and others prefer to handle errors using goto is that it avoids the main branch of the code receiving an additional indentation, as it would if it were wrapped in a conditional. Not to do so would make the code less readable.
Note that these gotos are always local jumps (that is, they are in the same code block), at the same indentation level, and they are forward jumps (so the control flow is much the same as for a conditional). They are easy to understand and audit, and not similar to the goto examples that Dijkstra criticised for making code hard to reason about.
- arnnr 15y agoThis. Also python's execeptions can be treated as limited goto's: http://docs.python.org/faq/design.html#why-is-there-no-goto http://docs.python.org/faq/design.html#why-is-there-no-goto