3 ms·
if (something) { blah(); goto fail; } ^^^ that part works if (something) blah(); goto fail; ^^^ that part is written in a misleading way and doesn't do w
by Piskvorrr 10y ago
if (something) {
blah();
goto fail;
}
^^^ that part works
if (something) blah(); goto fail;
^^^ that part is written in a misleading way and doesn't do what it seems to do on first glance.
It is unfortunate that the problematic line contained a jump, because "#gotofail" seems to convey "GOTO considered harmful", while it's something completely unrelated. Ironic, really, given the actual meaning of "human looks at a block of text and misparses it."
- cyphar 10y agoYou're conveniently not mentioning that this would cause very similar issues: if (some_cond) { goto fail; } goto fail; if (some_cond) { goto fail; } if (some_cond) { goto fail; } if (some_cond) { goto fail; } Is it more obvious? Sure. But the real issue is that they weren't testing all of the important failure cases, not that they weren't using one code style over another. Coding style is not going to help you if one of those some_cond values is incorrectly written...
- Piskvorrr 10y ago"More obvious" is precisely my point: the misindentation in your example jumps out at anyone familiar with the syntax. This is not an universal cure, and won't help you with other types of semantic errors: nothing is going to help you if you try to avoid thinking and rely solely on your tools; that is the essence of cargo-cult programming. OTOH, this tool will help you avoid a common pitfall with potentially disastrous consequences. A high-visibility vest for coding, if you will: won't save you from slipping or your head from falling objects, but neither is its purpose. (Iterative bootstrapping is how we got from sharpened rocks to virtual machines, not by "meh, this minor improvement won't fix everything, so why bother.")