> no white space after the keywords if, for, while, etc. Woh, my workplace enforces the exact opposite! The idea is that if, while, etc are not functions, therefore `if (x)` is unacceptable but `my_func(x)` is ok. I personally prefer `if(x)` though.
Plan 9 Coding Conventions for C
31–40 of 68 posts
Re: Plan 9 Coding Conventions for C
#32Earlier quoted context omitted.
And don't forget: if(a) if(b) x; else y; This doesn't do what the indentation implies. ( http://en.wikipedia.org/wiki/Dangling_else ) Walter Bright (creator of D, etc.) has an article where he discusses his interesting choice to make that grammar form illegal in D. He mentions that after doing this he found a bug in D's runtime library. http://www.drdobbs.com/cpp/dangling-else-yet-again/231602010
This makes a good point for Python syntax, where you can't by construction end up in situations like that.
Re: Plan 9 Coding Conventions for C
#33Earlier quoted context omitted.
Because developer one wrote if (statement) one; And developper two added if (statement) one; two; too quickly
The actual problem there is that developer two checked something in without thinking about it, reading it, or examining the diffs of the change. If you had a coding convention of always using braces in if statements, you might be insulated from this particular symptom or instance of the problem, but you still have the underlying problem that people are doing things without thinking.
People are fallible, mistakes get made.
Re: Plan 9 Coding Conventions for C
#34* variable and function names are all lowercase, with no underscores. That sounds odd
Re: Plan 9 Coding Conventions for C
#35Earlier quoted context omitted.
And don't forget: if(a) if(b) x; else y; This doesn't do what the indentation implies. ( http://en.wikipedia.org/wiki/Dangling_else ) Walter Bright (creator of D, etc.) has an article where he discusses his interesting choice to make that grammar form illegal in D. He mentions that after doing this he found a bug in D's runtime library. http://www.drdobbs.com/cpp/dangling-else-yet-again/231602010
This makes a good point for Python syntax, where you can't by construction end up in situations like that.
Re: Plan 9 Coding Conventions for C
#36* variable and function names are all lowercase, with no underscores. That sounds odd
Not really. Look at everything in the C standard library: fopen(), strcmp(), malloc(), etc.
Re: Plan 9 Coding Conventions for C
#37Earlier quoted context omitted.
OS code has to do a lot of validating input and braceful style causes functions to be visually dominated by boring validation code. It's also surprisingly nice to have a visual distinction between boring conditions like if(!found) return; and the more interesting branches that require the braces. Not sure I follow you on the one; two; example. Why would you have two statements per line in the first place? (You do rea…
Because developer one wrote if (statement) one; And developper two added if (statement) one; two; too quickly
#define one a;b;
if (statement) one;
Re: Plan 9 Coding Conventions for C
#38> no white space after the keywords if, for, while, etc. Woh, my workplace enforces the exact opposite! The idea is that if, while, etc are not functions, therefore `if (x)` is unacceptable but `my_func(x)` is ok. I personally prefer `if(x)` though.
There is no right or wrong here. The important thing is consistency across a project.