why no "do : until"?

Peter Hansen peter at engcorp.com
Tue Jan 2 23:48:49 EST 2001


"Samuel A. Falvo II" wrote:
> 
> That method is almost always self-inconsistent as well.  Most of the people
> I see using that technique writes code like this:
> 
> void f( int c )
> {
>    int x = 0;
> 
>    while( x < c )
>       {
>       printf( "X=%d\n", x );
>       x++;
>       }
> }
>
> To make it self-consistent, you need to do this:
> 
> void f2( int c )
>    {
>    int x = 0;
> 
>    while( x < c )
>       {
>       printf( "X=%d\n", x );
>       x++;
>       }
>    }

Phew!  I pass your self-consistency test! :-)  At first I did it
inconsistently, before I came to appreciate the inherent value of
consistency throughout.  Only problem I have is when I attempt to enclose
a block with braces strictly for scoping reasons -- I don't know whether
to indent the block or leave it outdented with the rest of the
instructions.  After all, there is no enclosing conditional or loop
structure:

void f()
    {
    int x;
    some code here;

    // dang: do I indent this or not?
    {
    int x;

    code that uses the inner x;
    }

    return;
    }


> However, the other view can also be considered -- the braces envelop a
> sequence of code to be treated as a single, logical statement, which of
> course statements like while() accept.  Thus, indenting them, along with the
> contained statements, also makes sense *if* you think of them in this way.

Exactly!  At least someone understands!  :-)

> There's really no right or wrong way -- it's all just a matter of personal
> preference.  

And that is pretty much inarguable.  

Except for the evil, ugly, inconsistent brace style which has the opening
brace on the end of a line and the closing brace outdented after the last
nested statement.  People who use that technique should be barred from
programming, not to mention shot.  I'd say "in my opinion" but of course
this is a matter of *fact* and not open to discussion, so there.  :-)



More information about the Python-list mailing list