> (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;

this (the former method) is good practice since mingling declaration and
initialization can lead to big copypasta errors if^w when the
code is reorganized.

> (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".

i think the plan 9 convention is to keep few enough globals
so than one can be expected to remember them.

> (4) In ARGBEGIN/ARGEND blocks, boolean switches are often set using the
> "++" operator rather than "|= 1", i.e.:

this is trivia.  (and i'd argue that generally both are wrong;
it's not a bit array, and the count is not important.)

> (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;

this is a variant of hungarian notation.  what value
does it add?  the declarations are clear enough.  everyone
knows what argv/argc are.

i've fallen into most of these traps myself.  i used to declare
main as main(int c, char **v).  what i found was fitting in
and understanding the whys of the local conventions is much
more important than whatever quirks you have yourself.

- erik

Reply via email to