5 ms·
For as long as I live, I’ll never understand style guides that permit omitting brackets around a single line following an if statement (or for, while, etc), nor
by bobbylarrybobby 6y ago
For as long as I live, I’ll never understand style guides that permit omitting brackets around a single line following an if statement (or for, while, etc), nor code formatters that dont automatically insert them.
- lucasyvas 6y agoI agree - it should be a compile or runtime error.
- umvi 6y agoWell if you compile with `-Werror -Wall` (and you should), it would throw in error in GCC 6+: https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail/ https://developers.redhat.com/blog/2016/02/26/gcc-6-wmislead...
- jimbob45 6y agoIt can make code bloated and harder to follow. TBH it would be nice if someone made C with indent scoping instead of block scoping but I don’t think that’s truly practical with the preprocessor.
- efwfwef 6y agoharder to follow? In what sense? Because in my book the fact that you can write both the line with braces and without make it much harder to think about, whereas in most other languages I don't need to think about it because there's only one way to write that.
- int_19h 6y agoWhat's the practical difference between: if (foo) bar; else baz; and: if (foo) { bar; } else { baz; } The latter has one extra line, which is hardly bloat. It also has the braces, of course, but the upside of this style is that it's clear where the compound statement begins (it's the line that doesn't start with a brace!), and where it continues.
- kevin_thibedeau 6y agoThey add visual noise. The grammar of C is not the same as the grammar of it's offshoots and block statements aren't part of control structures. Moreover, GCC warns about extra statements with the same indentation level with -Wall on.
- tpush 6y agoIMO you get accustomed to single statement-braces very quick and they leave less room for errors.
- efwfwef 6y agoand remove bugs
- coldtea 6y ago>They add visual noise. Which is a good thing, since it prevents errors such as this one. Extra verbosity with mandatory braces is noise (to the degree that without it, the compiler could still infer what we mean), but some degree of verbosity is a good thing, as it helps make patterns in the code more evident. In which case we might want to call it a more fitting error than the dismissing "noise". How about "dither"?
- mmis1000 6y agoThat is probably why styles like if (cond) { // statement } else { // statement } existed. Allow you to quote everything while not waste so much vertical space.
- efwfwef 6y agoI'm so glad that modern languages are opinionated and have default formaters that come with them. Jumping from one C codebase to another is really a nightmare, especially if you want to review code. That's a security issue in my book, as you end up with more reading complexity.
- xxpor 6y agoI'm convinced the GNU style is just for gatekeeping at this point. You REALLY have to want to work on a codebase with that after reading anything remotely Linux inspired.
- Gibbon1 6y agoFor as long at I live I'll never understand why why there wasn't a test suit to make sure that module and especially THAT module worked correctly. Changes were made to that module without tests being run and then it was put into production code.