Readable code (Was: Re: [H-GEN] Which is better?)

Greg Black gjb at gbch.net
Thu Apr 29 20:12:14 EDT 2004


On 2004-04-29, Anthony Towns wrote:
> On Thu, Apr 29, 2004 at 02:00:19PM +1000, Greg Black wrote:
> > Speaking of indent, does anybody know of an incantation to
> > either BSD or GNU indent to do K&R style but to leave the
> > following as is, rather than moving the lone semi-colon up to
> > the "for" line:
> >     for (p = buf; isspace(*p); ++p)
> >         ;
> > K&R style would leave it as is, but both versions of indent seem
> > to want to move it.
> 
> Personally, I'd make it "NULL;" or more likely rewrite it as:
> 
> 	p = buf;
> 	while (isspace(*p)) 
> 		p++;
> 
> When you're looking at a loop, you should be able to spot the stuff
> that takes the most effort by looking at the body, rather than the
> conditions, IMO.

We don't use indent to re-write our own stuff, but to re-write
stuff that others wrote that we want to read.  I took an actual
example from some such code.  If indent would just get this
right, it would be much more useful, at least to me.

Mind you, if it re-wrote it the way you suggest there, I'd be
happy with that too -- but that's a wee bit risky for something
like indent to do unless it graduates to being an option to gcc.

> (Hey, you said it was okay to avoid the question being asked, right?)

Did I say that?  Well it must be true.

Cheers, Greg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 249 bytes
Desc: not available
URL: <http://lists.humbug.org.au/pipermail/general/attachments/20040430/285d67d6/attachment.sig>


More information about the General mailing list