s***@icebubble.org
2012-01-11 18:41:19 UTC
Hello,
As readers may remember from a previous thread, I have historically
been, well, less than enamored with some aspects of the coding style
used in Plan 9/plan9port. Now that I'm getting into development, I'd
like to know what coding conventions the Plan 9 community endorses. I
have read the Plan 9 compiler paper, and understand the conventions
described in it. While conventions such as composing variable names
using lower case letters and no underscores do irk me a bit, I can live
with them---because those are the conventions that the community has
adopted. However, there are a number of stylistic features in Plan
9/p9p code which I've noticed (which AREN'T discussed in the compiler
paper) and I'm wondering whether they're intentional conventions or not.
(1) For example, P9 code tends to use variable names like "i" and "j",
where I would typically use self-documenting variable names like "row"
and "col". Variable names like "row" and "col" are much easier to
search for (i.e., with a right-click), too. Names like "i" and "j"
(which occur in many identifiers) will generate many false positives.
(2) In functions, variables are often declared together in one
paragraph, and then, later, initialized in another paragraph, as in:
int i;
char *s;
/* stuff */
i = 0;
s = nil;
rather than something like:
int i = 0;
char *s = nil;
(3) Lots of global variables are used, without any distinguishing
syntax, i.e. "char *f". I prefer to designate global variables with
something like a leading underscore, i.e. "char *_filename".
(4) In ARGBEGIN/ARGEND blocks, boolean switches are often set using the
"++" operator rather than "|= 1", i.e.:
case 'v':
verbose++;
case 'x':
x++;
as opposed to:
case 'v':
verbose++;
case 'x':
x |= 1;
(5) P9 code tends to repeat constructs such as "argv[i]" over and over
throughout the code, like:
for(i = 0; i < argc; i++){
somestuff(argv[i]);
otherstuff(argv[i]);
}
whereas I would typically use something like:
int argnum;
char *argstr;
for(argnum = 0; argnum < argc; argnum++){
argstr = argv[argnum];
somestuff(argstr);
otherstuff(argstr);
}
Are these practices official/unofficial Plan 9 coding conventions? Are
they used for performance purposes? Are they just poor style? Or has
this kind of style been used for so long that it's BECOME Plan 9's style
of choice? Also, is it considered polite or acceptable coding practice
to alter the style of code written by other contributors? I don't want
to step on anybody's toes by "fixing" style which other Plan 9
developers consider to be "Plan 9" style coding conventions.
Thanks!
As readers may remember from a previous thread, I have historically
been, well, less than enamored with some aspects of the coding style
used in Plan 9/plan9port. Now that I'm getting into development, I'd
like to know what coding conventions the Plan 9 community endorses. I
have read the Plan 9 compiler paper, and understand the conventions
described in it. While conventions such as composing variable names
using lower case letters and no underscores do irk me a bit, I can live
with them---because those are the conventions that the community has
adopted. However, there are a number of stylistic features in Plan
9/p9p code which I've noticed (which AREN'T discussed in the compiler
paper) and I'm wondering whether they're intentional conventions or not.
(1) For example, P9 code tends to use variable names like "i" and "j",
where I would typically use self-documenting variable names like "row"
and "col". Variable names like "row" and "col" are much easier to
search for (i.e., with a right-click), too. Names like "i" and "j"
(which occur in many identifiers) will generate many false positives.
(2) In functions, variables are often declared together in one
paragraph, and then, later, initialized in another paragraph, as in:
int i;
char *s;
/* stuff */
i = 0;
s = nil;
rather than something like:
int i = 0;
char *s = nil;
(3) Lots of global variables are used, without any distinguishing
syntax, i.e. "char *f". I prefer to designate global variables with
something like a leading underscore, i.e. "char *_filename".
(4) In ARGBEGIN/ARGEND blocks, boolean switches are often set using the
"++" operator rather than "|= 1", i.e.:
case 'v':
verbose++;
case 'x':
x++;
as opposed to:
case 'v':
verbose++;
case 'x':
x |= 1;
(5) P9 code tends to repeat constructs such as "argv[i]" over and over
throughout the code, like:
for(i = 0; i < argc; i++){
somestuff(argv[i]);
otherstuff(argv[i]);
}
whereas I would typically use something like:
int argnum;
char *argstr;
for(argnum = 0; argnum < argc; argnum++){
argstr = argv[argnum];
somestuff(argstr);
otherstuff(argstr);
}
Are these practices official/unofficial Plan 9 coding conventions? Are
they used for performance purposes? Are they just poor style? Or has
this kind of style been used for so long that it's BECOME Plan 9's style
of choice? Also, is it considered polite or acceptable coding practice
to alter the style of code written by other contributors? I don't want
to step on anybody's toes by "fixing" style which other Plan 9
developers consider to be "Plan 9" style coding conventions.
Thanks!
--
+---------------------------------------------------------------+
|Smiley <***@icebubble.org> PGP key ID: BC549F8B |
|Fingerprint: 9329 DB4A 30F5 6EDA D2BA 3489 DAB7 555A BC54 9F8B|
+---------------------------------------------------------------+
+---------------------------------------------------------------+
|Smiley <***@icebubble.org> PGP key ID: BC549F8B |
|Fingerprint: 9329 DB4A 30F5 6EDA D2BA 3489 DAB7 555A BC54 9F8B|
+---------------------------------------------------------------+