Live data from Hacker News

Plan 9 Coding Conventions for C

plan9.bell-labs.com

1–10 of 68 posts

Re: Plan 9 Coding Conventions for C

#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 (always use braces).

Otherwise you end up with things like:

   if (statement)
      one; two;

Re: Plan 9 Coding Conventions for C

#5

eg: http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/ramfs.c

Anybody know what the:

  int needfid[] = {
	[Tversion] 0,
	[Tflush] 0,
	[Tauth] 0,
syntax means? Is this some Plan 9 extension, or is it just something I've never encountered?

EDIT: I guess the value in the []'s is the array index to set the value of.

Re: Plan 9 Coding Conventions for C

#6
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…

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 realize that the "two;" isn't in the if block, right?)

Re: Plan 9 Coding Conventions for C

#7
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…

but two statements in one line is not exactly encouraged by the rules either.

Re: Plan 9 Coding Conventions for C

#10
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…

my favorite is

  if (statement)
  //  one;
    two;
Post reply on HN