Live data from Hacker News

Plan 9 Coding Conventions for C

plan9.bell-labs.com

41–50 of 68 posts

Re: Plan 9 Coding Conventions for C

#41

Earlier quoted context omitted.

Because developer one wrote if (statement) one; And developper two added if (statement) one; two; too quickly

Sure, but how often does this happen in practice? I have worked with 'no convention'/'multiple conventions'/'mostly no braces for single statements' and have never seen this particular mistake. I can see how it would be difficult to track down, on the other hand, braces for single comments add to line noise.

I've worked on multi-million line projects and have also never seen this mistake made. So in my experience, it is so vanishingly rare that the costs in visual gunk and decreased code density are not worth it.

A lint tool checking for suspicious indentation would be a better use of labour.

Re: Plan 9 Coding Conventions for C

#42
post #16
post #2

I appreciate that these are old rules, nevertheless, I have the following comments: don't use // comments; some old Plan 9 code does, but we're converting it as we touch it. We do sometimes use // to comment–out a few lines of code. Doesn't make sense with any decent editor, you ought to comment via macros. no braces around single–line blocks (e.g., if, for, and while bodies) I kind of like enforcing the opposite (al…

I can't stand macro comments - it makes it impossible to figure out whats going on without being sure to open the file in a specific editor with a specific project loaded. Say you have a separate lib project used by an application - if you open up an individual file from that lib while working on the application in Visual Studio it won't have the necessary context to 'comment out' macro comments. Its also hostile to…

Sorry if I'm unenlightened... but what are macro comments?

Re: Plan 9 Coding Conventions for C

#44
post #35

Earlier quoted context omitted.

This makes a good point for Python syntax, where you can't by construction end up in situations like that.

True, but the flip side is that in Python automatic indentation cannot possibly work.

Why not? vim indents one more when encountering a colon at the end of a line. It also de-indents when encountering a return or break statement. Of course in all other cases you have to de-indent manually, however, hitting backspace once is not more work than typing a closing curly brace.

Re: Plan 9 Coding Conventions for C

#45
post #42
post #16

Earlier quoted context omitted.

I can't stand macro comments - it makes it impossible to figure out whats going on without being sure to open the file in a specific editor with a specific project loaded. Say you have a separate lib project used by an application - if you open up an individual file from that lib while working on the application in Visual Studio it won't have the necessary context to 'comment out' macro comments. Its also hostile to…

Sorry if I'm unenlightened... but what are macro comments?

  printf("Legit code\n");

  #if 0
    /* bunch of code to comment out */
    printf("Commented code\n");
  #endif

Re: Plan 9 Coding Conventions for C

#47

Probably my favorite take-away from this: "Ultimately, the goal is to write code that fits in with the other code around it and the system as a whole. If the file you are editing already deviates from these guidelines, do what it does. After you edit a file, a reader should not be able to tell just from coding style which parts you worked on." This is a real boon to other people on your team.

Most good professionals I have worked with adhere to this simple rule.

Re: Plan 9 Coding Conventions for C

#49
post #44
post #35

Earlier quoted context omitted.

True, but the flip side is that in Python automatic indentation cannot possibly work.

Why not? vim indents one more when encountering a colon at the end of a line. It also de-indents when encountering a return or break statement. Of course in all other cases you have to de-indent manually, however, hitting backspace once is not more work than typing a closing curly brace.

What I mean is that you can't tell your editor to indent an arbitrary block of code.
Post reply on HN