2 ms·
Not sure what the "technical drawbacks" are, unless doThisOneLinerWithoutCurlyBraces is a macro and the author didn't think to do the do { } while (0) trick. Th
by asveikau 13y ago
Not sure what the "technical drawbacks" are, unless doThisOneLinerWithoutCurlyBraces is a macro and the author didn't think to do the do { } while (0) trick. The Linux kernel coding style actually advocates this style: http://lxr.linux.no/linux+v3.12.6/Documentation/CodingStyle http://lxr.linux.no/linux+v3.12.6/Documentation/CodingStyle (line 157, "Do not unnecessarily use braces where a single statement will do.")
I agree with what you're saying though. Making whitespace differences into a build break seems to miss the point a bit. Is that what the author thinks "clean code" means? Consistent whitespace and nothing more? Consistent whitespace is certainly a good idea but there's so much more to a sane code base than how many newlines follow a declaration or whatever.
- reginaldjcooper 13y agoWithout curly braces it is simpler to mess up if you revisit the code, maybe especially adding ambiguous else conditions. I'm sure you and the GP would never forget to add curly braces when inserting an else, but the junior developer who comes afterwards might, and it's just not a huge deal to have the braces because it's two extra chars. Quite frankly the Linux kernel coding style is wrong on this one in general, I guess we can assume they are experienced enough to put braces in when adding an else clause and so it's not going to cause them errors. But with junior devs it certainly could.
- asveikau 13y agoI definitely don't agree with everything in that style guide either, but I can respect it. I think what I like the most is that it's non-judgmental (or when it is judgmental it is clearly sarcasm). It has nice blurbs like "Please at least consider the points made here." - which is the right attitude for a style guide.
- gurkendoktor 13y agoIf you are worried about else conditions, wouldn't this be the way around it? {if (condition) singleFunctionCall();}
- gurkendoktor 13y agoWhy is this being downvoted? How do curly braces around the function call help with ambiguous else branches?