|
It's too often that single statements turn into multiple statements and you forget to add braces. So allways add the braces from the very beginning.
|
|
|
|
|
henningbenk wrote: single statements turn into multiple statements and you forget to add braces
I've made thousands of stupid errors in my career so far, but have yet to do that. How is this not obviously wrong, unless you code with Python?
if (something)
do1();
do2();
In fact most compilers will issue a warning for that nowadays.
|
|
|
|
|
Nemanja Trifunovic wrote: I've made thousands of stupid errors in my career so far, but have yet to do that.
Agreed.
|
|
|
|
|
I've seen that exact problem come up before, usually in a rush when people are feverishly trying to meet a deadline. Thankfully it's only happened a couple of times but it's a real PITA to debug when it happens.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."
-- Marcus Brigstocke, British Comedian
|
|
|
|
|
Nemanja Trifunovic wrote: I've made thousands of stupid errors in my career so far, but have yet to do that.
Ditto.
Kevin
|
|
|
|
|
That is only a problem if you put the single statement on a new line. When I do that, I always add the braces from the beginning, but if the single statement is simple and short, such as a simple value assignment (if (fruitType == banana) color = yellow;), it all goes on one line. If you add another statement to this 'if' claues, you move the first assignment down and add the braces.
Never an indent without a brace on the line above!
|
|
|
|
|
but it depends on the situation.
|
|
|
|