7 ms·
He already used the right brace style (hanging braces, cuddled else) and the right indentation (tabs, not spaces).
by mseepgood 13y ago
He already used the right brace style (hanging braces, cuddled else) and the right indentation (tabs, not spaces).
- comex 13y agoSomehow over the years learning C on my own, perhaps because it seemed more consistent to me, I got used to writing if(foo) { omitting the space after control statements' names, which is almost never done - except in very early C code. (It's not just this: V7 Unix often omits the space as well.). I should probably settle on a less idiosyncratic personal style, but I can't help but take a little heart from seeing "my" style in such a famous codebase. :)
- PySlice 13y agoNever using a space before the paren is more consistent. I don't know why people put a space there...
- brianberns 13y agoif(foo) I avoid doing this because it looks like a function call.
- kybernetikos 13y agoIn an appropriately powerful language, it could be a function call.
- a1369209993 13y agoafter #define if(X) LET(_it,X) if (_it) it would be a macro call
- yoklov 13y agoI'm fairly certain that shadowing a keyword with a macro is forbidden by the standard (or invokes UB?) but this will still work for most compilers, provided LET is defined reasonably. Hm, something like #define LET(name, X) \ for (int let_once_=1, name=(X); \ let_once_; \ let_once_=0) may be reasonable, though tokenpasting in __LINE__ for good measure might be necessary for nesting.
- 30thElement 13y agoShadowing keywords is perfectly valid, although I believe you can't shadow keywords in standard headers so that compiler writers don't need to worry about it. It gives rise to some "useful" C/C++ features that should never be used, like if you want to access private members in foo.cpp, do #define private public #include "foo.cpp" #undef private
- TazeTSchnitzel 13y agoI can imagine some insidious menace adding this to the top of a file: #define public protected
- yoklov 13y agoI once someone jokingly do (the second only always works in C, not C++) #define else #define struct union Evil!
- mseepgood 13y agoIt was also defined in the Plan 9 code style: http://plan9.bell-labs.com/magic/man2html/6/style http://plan9.bell-labs.com/magic/man2html/6/style "no white space after the keywords if, for, while, etc."
- brokenparser 13y agoIndentation, yes. Braces, no. He uses K&R style because he was the R (obviously). But nothing new is being written in K&R C these days, favouring ANSI C (99/11 or 89 if you're stuck on cl) with usually Allman/KNF style or a variation thereof instead.
- Mr_T_ 13y agoRecently some ignorant, nescient C++ programmer called me a Java programmer, because I use K&R style and not his preferred Allman style. Even Stroustrup uses hanging braces (with the exception of function body opening braces)!
- reledi 13y agoYour comment is flamebait.
- Peaker 13y agotabs are an infinite source of pain and inconsistencies... Everyone must support the space character, it cannot be banned. But a simple commit hook to ban tabs can make indentation and alignment not get messed up over time with many collaborators with default-configured editors (that mess up and use tabs for alignment).
- mikeash 13y agoThe inventor of the tab character is on my list of people to assassinate when they're young if I ever get access to a time machine, the other people on the list being Hitler and Charles Douglass. The tab character is a nice idea, but they do not seem to have worked out at all. I'd much rather have syntax-aware indenting in the editor, now that available compiler technology and CPU power make it practical.
- ma2rten 13y agoI am just thinking, why not solve this at the scm level, e.g. make a git plugin that will check out the sources indentation independent and only show changes to contents of the file not the indentation. You could even make a plugin that works without collaboration by others: check out the file in your preferred style and transform the changes back into the original style.
- mikeash 13y agoI totally agree. I seem to recall an experimental clang-based git plugin for this floating around. I think it even handled certain differences in naming convention. We'll probably get there in a few more years, as we get comfortable with adding more power to these systems, and taking advantage of compiler technology for things other than generating code.
- GnarfGnarf 13y agoI don't understand what's so bad about tabs. With tabs, all you have to do is adjust the settings in your editor, and each programmer gets the indentation (s)he wants: 2, 4, 8, whatever... Also, do you really want to be pressing the space bar twelve times, instead of tabbing three times? I've seen the results of spaces-only: inconsistent, sloppy indentation, 7 or 9 spaces instead of 8, as long as it looks "indented" enough. How, specifically does the tab character "not seem to have worked out at all"? I'm not saying you're wrong for using spaces, just wondering...