|
|
|
|
|
by climb_stealth
568 days ago
|
|
I was thinking of a case like this: if (foo)
return;
Perfectly valid and people do it. But then later on someone might put a debug statement above the return to check something. Or add some other logic. if (foo)
doSomething();
return;
And suddenly the logic is broken and the return falls out of the if-condition. It looks fairly contrived with an example like this but easy to do when code is a bit more complicated or people are tired or rushed. It's a good habit to always enforce braces for if-conditions as it defeats that whole category of mistakes. Fairly innocent but can be so hard to find because of that.A linter would enforce having braces and solve the issue. And for codebases without a linter it is a good habit to just go with the braces. |
|