From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Wed, 11 Jan 2012 15:45:28 -0500 To: 9fans@9fans.net Message-ID: In-Reply-To: <86vcoif5f4.fsf@cmarib.ramside> References: <86vcoif5f4.fsf@cmarib.ramside> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] Plan 9/plan9port coding conventions Topicbox-Message-UUID: 582d1b3e-ead7-11e9-9d60-3106f5b1d025 > (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