9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Plan 9's style(6) manual page
@ 2018-04-07 16:00 8halfan
  2018-04-07 17:47 ` Jules Merit
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: 8halfan @ 2018-04-07 16:00 UTC (permalink / raw)
  To: 9fans

Just an amateur C programmer looking for answers. My main inspirations
for code
style is K&R 2nd edition and I'm curious about the instructions in Plan
9's
style(6) manual page (for reference,
http://man.cat-v.org/plan_9/6/style). I've
tried to think about the motivations, but not everything is as clear as
it
seems.

Going through style(6):

> no white space before opening braces.
> no white space after the keywords `if', `for', `while', etc.

This is unique to Plan 9, it seems. I can't come up with a reason --
both BSD
and Linux style use whitespace, and K&R does too, while Plan 9 doesn't.
Why?

> no braces around single-line blocks (e.g., `if', `for', and `while'
> bodies).

Apologies, but I'll have to Go and do it anyway :)

> automatic variables (local variables inside a function) are never
> initialized at declaration.

Why not? In order to reduce visual clutter? It seems like this should be
handled
case-by-case: in some situations this just wastes lines:

	int foo;
	foo = 12;
	func("blah", &foo);

> follow the standard idioms: use `x < 0' not `0 > x', etc.

I'm guessing this is for consistency and more common coincidence with
the flow
of spoken language.

> don't write `!strcmp' (nor `!memcmp', etc.) nor `if(memcmp(a, b, c))';
> always
> explicitly compare the result of string or memory comparison with zero
> using a
> relational operator.

Was that a common programmer error? cmp functions should return 0 if the
arguments are identical. Smells like disaster in baking!

> and this is not an exhaustive list

Is there anything missing?

That's all. Thanks for your time.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-04-08  4:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-07 16:00 [9fans] Plan 9's style(6) manual page 8halfan
2018-04-07 17:47 ` Jules Merit
2018-04-07 17:59 ` Digby R.S. Tarvin
2018-04-07 19:11   ` hiro
2018-04-07 20:14 ` Ori Bernstein
2018-04-07 20:38   ` tlaronde
2018-04-07 20:42   ` Skip Tavakkolian
2018-04-08  4:38   ` Rob Ote

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).