for loop fixes

David Elliott dfe at infinite-internet.net
Sun Mar 4 06:21:22 CST 2001


Andreas Mohr wrote:

> On Sat, Mar 03, 2001 at 07:17:41PM -0800, Francois Gouget wrote:
> > On Sat, 3 Mar 2001, Andreas Mohr wrote:
> > [...]
> > > - changed all terminating ";" of isolated for loops to " ;" to indicate the
> > >   loop's isolation.
> >
> >    IMHO, for such loops the following would be much clearer:
> >
> >    <init_expression>;
> >    while (<test_condition>) {
> >      <update_expression>;
> >    }
> >
> >   (ok, you can also put '{' on the next line)
> Right.
>

Why, what's wrong with a for loop?

So far we have these choices:
for(init,test,update); /* original */
for(init,test,update) ; /* with space */
init;
while(test)
{
    update;
}

What about simply:
for(init,test,update)
    ;

Putting the semicolon on the next line indented makes sense IMHO.  Solves the
problem of confusing it with a for loop accidently having a semicolon at the end
and these kind that intentionally have one and is visible to a human at a very very
quick glance.  The only expense is ONE line.

>
> > > Please do the same for these for loops in the future.
> >
> >    ???
> Well, I just meant that they should always use " ;" instead of ";".
> But your proposal is probably much better.
>

I dunno, I like mine but shit we are gonna start a really bad coding-style war here
if we continue with this.

>
> > > Somebody might want to write a Wine coding guidelines article...
> >
> > $ wg . -E 'for *\(' | grep -E '\) *; *$'` | wc -l
> >      96
> >
> >    (wg is my recursive source grep script)
> >
> >    Maybe we should ask people to put the for and the instruction it
> > applies to on separate lines. Combined with the suggestion above this
> > would make it easier to check for this kind of bug.
> Correct.

Just don't specify an indentation style, lest we be stuck with 2 or 3 spaces for an
indent instead of a nice single 8-space tab (am I the only one here who prefers
tabs to spaces?)

As far as specifying using while instead of for, I am not such a big fan of that
either.  Personally I feel whoever is writing the code should decide.  Requiring a
space between the ) and ; or requiring the semicolon on the next line indented once
more is probably the best way to go.  Even an either-or approach on this would be
acceptable.


> > > P.S.: I just *knew* that at least one other for loop in Wine would be wrong,
> > > too ;-)
> >
> >    Yep, I should have done that myself (if you find a generic bug,
> > always check for other similar bugs).
> I always do that when someone spots a generic bug :-)
>

Surprised there was only one of these that was for real incorrect.  I have
accidently put that semicolon there on several late-night programming sessions.
Usually you catch it pretty quick though since when you run the code it does some
really strange shit.

-Dave





More information about the wine-devel mailing list