delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/09/13:00:07

Sender: crough45 AT amc DOT de
Message-Id: <97Oct9.185357gmt+0100.11651@internet01.amc.de>
Date: Thu, 9 Oct 1997 17:58:25 +0100
From: Chris Croughton <crough45 AT amc DOT de>
Mime-Version: 1.0
To: beroset AT mindspring DOT com
Cc: djgpp AT delorie DOT com
Subject: Re: ccoding empty loops

Ed Beroset wrote:

> > - and in fact violates the coding standards of the last
> > three places I worked at. 8-)
> 
> How very odd.  Do those coding standards state something like, "all
> while statements shall have curly braces" or do they have some specific
> prohibition against the "continue" keyword?

Not at all odd.  Most coding standards I've seen insist on braces
on all controlled statements - if, while, do, for, etc.  Particularly
when developing code it avoids problems when inserting statements.  
For instance:

Original code:

  if (x < y)
    x = y;

Then you realise you want to do something as well.  It's very easy
to end up with something like:

  if (x < y)
    x = y;
    a[x] = y*y;

and not notice that the second statement isn't actually controlled
by the if.  It's even worse if you're used to seeing K&R type
braces like

  if (x < y) {
    x = y;
    a[x] = y*y;
  }

It also minimises the risk of doing something else wrong while 
editing - you can delete a statement without having to delete the
braces as well (and seveal times I've deleted one line too many).

(Auto-indenters don't help when it's C++ instead of C, they break.
Unless the GNU people have upgraded indent recently, but from what
I heard they weren't interested because the 'official' language
of GNU is C.)

Chris C

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019