Subject: Re: commoning up code that changes uids and gids
To: David Laight <email@example.com>
From: Greg A. Woods <firstname.lastname@example.org>
Date: 04/05/2003 17:21:00
[ On Saturday, April 5, 2003 at 22:39:24 (+0100), David Laight wrote: ]
> Subject: Re: commoning up code that changes uids and gids
> > > for instance how would you read:
> > > svuid = 1 + (ruid == p->p_cred->p_ruid) ? -1 : euid;
> > In the first place, I'd write this as
> > svuid = 1 + ((ruid == p->p_cred->p_ruid) ? -1 : euid);
> > and thus would not have any problem reading it. Parenthesis good.
> I thought you might :-) which indicates that the parenthesis confused you!
> Learn table 2-1 (P53 of K&R 2), it isn't hard.
Learning that table, even having a very deep understaning of it and all
the underlying concepts it is based on, doesn't necessarily help with
readability issues one tiny little bit. Readability is about something
> Personally I find that, in complex expressions, unnecessary parenthesis
> make parsing harder not easier.
You should learn lisp (or use it more often if you do know it already),
then you hopefully wouldn't have that problem.
In languages like C parenthesis are almost always put there purely for
the purposes of enhancing readability. They are not really ever
necessary as every expression can be rewritten, perhaps in multiple
steps, to do without them. Remember too that readability issues have
many levels -- they range from little hints to lead the eye to
higher-level groupings and separations to aid conceptual understanding.
> The () around the first operand of ?:
> are particulaly pointless, as are those the the RHS of = (and other
> assignment operators).
The parens around the first operand of ?: expressions are pointless only
to the compiler. They are extremely valuable low-level readability
hints for humans. They tell the reader's eyes to play closer attention
to what comes next and to not treat the next bit of whitespace as a
plain old term separator but to rather recurse into a new
> After all you don't use () around ->  and .
That's because you also don't usually put any whitespace around those
Greg A. Woods
+1 416 218-0098; <email@example.com>; <firstname.lastname@example.org>
Planix, Inc. <email@example.com>; VE3TCP; Secrets of the Weird <firstname.lastname@example.org>