6 ms·
For a relatively recent problem caused by use of goto: https://en.m.wikipedia.org/?title=Goto_fail https://en.m.wikipedia.org/?title=Goto_fail
by praptak 8y ago
For a relatively recent problem caused by use of goto: https://en.m.wikipedia.org/?title=Goto_fail https://en.m.wikipedia.org/?title=Goto_fail
- Sniffnoy 8y agoNon-mobile link: https://en.wikipedia.org/wiki/Unreachable_code#goto_fail_bug https://en.wikipedia.org/wiki/Unreachable_code#goto_fail_bug
- zzo38computer 8y agoThat is not specific to do with a goto command itself; even if you wrote "break" instead of "goto fail", still the second one is unconditional. But either way, can easily seen that such program is not sense, so, easily to be noticed. "There are several good coding practices that could have prevented this fault from occurring, such as code reviews, the proper use of indentation or curly braces, and test coverage analysis." Yes, it is true, whether you use goto or not, whether indentation-sensitive syntax is used or not, etc.
- RustHacker 8y agoBreak is technically a goto, albeit a nicer, more well behaved version thereof.
- goto11 8y agoThe problem is not caused by the use of goto though. It could have been any other statement and it would still be a bug. The problem is lack of braces or the misleading indent. If anything this example is a case for Python, not a case against goto.
- coldtea 8y ago>If anything this example is a case for Python, not a case against goto. You'd be surprised how many times I've got the indentation wrong in Python. If a body gets > 20 lines or so, it's easy to miss one statement that ought to be intended.
- int_19h 8y agoThis example is a case for languages where the bodies of conditionals, loops etc are required to have a terminator. Python is technically one of them, but probably not the best one, because terminator is the DEDENT pseudo-token, and because it's just whitespace, it can be easy to miss. The best examples are languages like Lua and Ruby, where you have to write it as if .. then .. end or if .. then .. else .. end. Alternatively, in the curly brace family, it's the ones that make braces mandatory in this situation, like Go - if ... { ... }.
- deleted 8y ago[deleted]