3 ms·
The 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 mi
by goto11 8y ago
The 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 ... { ... }.
- goto11 8y agoAgree, and I am paranoid enough to always use braces for single statement bodies. I also think this is recognized as a flaw in C-style syntax, and newer languages like Rust mandate the braces. I do think Python has the simplest and most logical solution though.
- robotnik 8y agoThe editor should have indented that line correctly.