4 ms·
Can't you make the argument that even in C/C++ they could have enforced different "Language rules" like forcing no warnings? When compiling with gcc you could u
by blueblob 13y ago
Can't you make the argument that even in C/C++ they could have enforced different "Language rules" like forcing no warnings? When compiling with gcc you could use -Wunreachable-code. Then it is part of the process.
EDIT: with -Werror it will make this bug an error but not necessarily the class of bugs.
- eldude 13y agoOf course. I didn't want to muddie the issue, but I would consider compilation flags, transpilation (e.g., coffeescript) and linting (e.g., jshint, etc...) to reside between "Language rules" and "Unit tests."
- Peaker 13y agogcc has not warned about unreachable code for years[1] now :( clang -Wunreachable-code does, though. [1]: http://gcc.gnu.org/ml/gcc-help/2011-05/msg00360.html http://gcc.gnu.org/ml/gcc-help/2011-05/msg00360.html
- blueblob 13y agoWow, that's interesting! Thanks for that. I just saw it in a manpage, didn't realize it doesn't currently work. That's what I get for R-ingTFM :-D
- gweinberg 13y agoan unreachable code warning would have caught this particular defect, but it wouldn't have helped if the duplicated line were something other than a goto. I think the policy of always using curly braces for conditionals (even if only one line) in c like languages is a good one.
- AnthonyMouse 13y ago> an unreachable code warning would have caught this particular defect, but it wouldn't have helped if the duplicated line were something other than a goto. In that case always using curly braces or using a language that requires an "end" statement after the conditionally executed code may not have helped either. Imagine the incorrectly repeated statement was "a = a + 1" or "error_mask ^= error_x" etc. Putting the erroneous line inside the conditional doesn't erase the error, it just modifies the conditions under which it executes. That's about as likely to hang you as save you.
- lukeschlather 13y agoIs there any language rule that can save you from incorrectly repeating an operation that is not idempotent?