3 ms·
goto is one of those things that you're actively discouraged from using or ever thinking about without ever knowing why or having to read "Goto Considered Harmf
by noobermin 7y ago
goto is one of those things that you're actively discouraged from using or ever thinking about without ever knowing why or having to read "Goto Considered Harmful." goto at least in C is the only way to implement exception handling in a way that properly separates the good path from the bad path without having many sets of nested conditionals after which most of the line becomes whitespace. It is also the only way to exit a deeply nested loop as well. It should be discouraged, especially jumping backwards, but it is necessary in some few cases, at least in C particularly.
- Someone 7y agoI think Dijkstra would say that C is lacking some essential higher-level constructs, not that goto has its uses.
- TazeTSchnitzel 7y agoI think goto in C with its labels, as a last resort where C's library of structured control flow constructs fail, is a much less bad thing than GOTO in BASIC with its line numbers and much more limited structured control flow.
- dfox 7y agoYou can implement sane exception handling in C by the means of few simple preprocessor macros. In fact, this is how exception handling is implemented in ObjectiveC and how it is done in Windows (and this hack is also the reason why Windows have three different ABIs wrt. exception handling) And in fact, implementing Common Lisp style condition system that can be used from C code in reasonably straightforward way involves only 1kLoC of cpp magic, been there, done that ;)