4 ms·
And the coding style doesn't exactly avoid errors as well. "Do not unnecessarily use braces around a single statement: if (condition) action(); a
by rgj 11y ago
And the coding style doesn't exactly avoid errors as well.
"Do not unnecessarily use braces around a single statement:
if (condition)
action();
and
if (condition)
do_this();
else
do_that();
"
Didn't people learn from the goto fail bug ?
http://embeddedgurus.com/barr-code/2014/03/apples-gotofail-ssl-security-bug-was-easily-preventable/ http://embeddedgurus.com/barr-code/2014/03/apples-gotofail-s...
- kstrauser 11y ago> Do not unnecessarily use braces around a single statement If you consider all braces to be necessary, then that's a truism and you can safely ignore it. "I didn't unnecessarily use them: we always use them because that's the safe thing to do."
- sjolsen 11y agoMaybe the coding standard was written by someone who was used to auto-indentation making this sort of mistake immediately obvious.
- tracker1 11y agoPersonally, I say if a statement continues on a different line, then you should use braces //okay if (condition) return foo; //not okay if (condition) return foo; //not okay if (condition) do_foo(); else do_bar(); In the second case, the else can be considered a continuation. In the first example, there's little chance of confusion or the introduction of an error, in the second and third, that is not necessarily the case. If it doesn't look/fit well on one line, break it up with braces.
- breakingcups 11y agoWhat about: if((somevar != checkvar((byte)othervar)) & (i != 3)) somefunc(); someotherfunc(); A bit exaggerating, I agree, but not far off from some real-world examples and quite confusing.
- tracker1 11y agoNice, in that case, I might advocate for either somefunc or a function in front of it taking somevar, othervar and i as parameters with early return statements before falling through to the work.. returning a boolean for if they passed through... I've seen far, far, far worse...