Talk:Developer C Coding Standard
From The Neuros Technology Wiki
I think screen space is *always* at a premium. Code does not become less complex if you space it out. Conversely, being able to see more of it at once is always a benefit (as long as it is still indented well, and blank lines are used consistently).
I do agree with using a healthy dose of intra-line spacing though, such as using "if ((blah && jim) || stuff) {" rather than "if(blah&&jim||stuff){".
--Chreekat 19:17, 6 November 2006 (CST) modified to make it look like I own both paragraphs above, which I do ;)
I do agree with the other two posts above, and FWIW, I find the K&R bracing easier to read. But then again, that's just my $0.02. I definitely agree with chreekat, though, on the intra-line spacing: if ((blah && jim) || stuff) {
--Shadyman 15:43, 6 November 2006 (CST)
I agree with Shadyman. I personally like K&R braces, but with intuitive spacing as I showed on the example. That's how I do it. Spaces between logical blocks of code...I'd give a for loop a linebreak on either side (minus comments). I also give variable declarations a linebreak. I find BSD/Allman rather awkward and not very intuitive. I suppose my love of K&R comes from not only K&R its self, but the fact that PHP code is normally K&R, which was my first language and I've now been doing it for over 5 years now. Here's an example of something I'd write using my conventions.
#include <stdio.h>
int main() {
int i;
printf("---Start---\n");
/* Useless loop. */
for (i = 0; i < 10; i++) {
printf("%d\n", i);
}
printf("---Done---\n");
/* Example of a 'logical' block, being that its function is completely separate of others. */
return 0;
}
K&R bracing, "intuitive" logical block spacing, 4 space indents, spacing between elements (e.g. if (blah && blah || stuff) {)
We also need to discuss prototypes and comments. When trying to doxygen documentation for neuros cooler I found it incredibly difficult seeing as all the comments for the functions were not with the headers, but rather with the actual code. This might be a standard we need to revise.
--Xorlev 18:36, 6 November 2006 (CST)
To play the Devil's advocate, the terminology "intuitive" logical block spacing is, and always will be, hopelessly ambiguous. :)
Seriously though, I think mgao's "Xiamen standard" is best: (paraphrasing his post to the ML)
- When editing existing code, respect the existing standard
- When creating new files, do whatever you want but be consistent
- (direct quote) Your patch will be brute-force rejected if otherwise. ;)
We are a team with no dictatorial controller; we should all be flexible to each other's styles.
--Chreekat 19:17, 6 November 2006 (CST)
This is true, my terminology is hopelessly ambiguous, but it's the best way to describe my warped ideas. It's intuitive for me to separate blocks of code in logical groupings. Perhaps I can come up with a better name, such as "subjective block spacing" or something like that. Either way, good spacing is something I feel is critical to code.
I'll write up a section with the Xiamen standard, but this page can give a few good tips on standards that help us all, and then provide a "recommended" standard as long as it doesn't interfere with the current standards as the Xiamen standard says.
--Xorlev 19:34, 6 November 2006 (CST)
[edit] Brace Style
Can we all agree on a brace style to recommend? I vote K&R, what do you think? Once we determine this we can move on to specifics.
--Xorlev 19:06, 7 November 2006 (CST)
I vote K&R with the exception that in the article, I think it should say for (x; x < 10; ++x) { instead of for (x; x < 10; ++x){ --Shadyman 21:35, 7 November 2006 (CST)
(Edit: Thanks, Xorlev, for fixing it up) --Shadyman 20:42, 8 November 2006 (CST)
Vote Shadyman ( K&R with space before { ) --Daurnimator
[edit] Use GNU Indent!
If developers simply agree on a GNU ident style to use before committing their code, everyone can use their own style and submit versions processed by indent. --Pgunn 13:01, 14 November 2006 (CST)
