:: Re: [DNG] Studying C as told. (For …
Startseite
Nachricht löschen
Nachricht beantworten
Autor: Rainer Weikusat
Datum:  
To: dng
Betreff: Re: [DNG] Studying C as told. (For help)
Peter Olson <peabo@???> writes:
>> On June 23, 2016 at 10:48 AM Edward Bartolo <edbarx@???> wrote:
>>   if (count > 0)
>>     while(putchar(' ') && --count);

>
> I strongly recommend using the continue statement here:
>
>       while(putchar(' ') && --count) continue;


I and I strongly recommend against it. The continue has absolutely no
meaning here which means its only conceivable effect is to puzzle the
reader. Insofar inline documentation is desired, the way to include it
are comments, not technically functionless statements at whose intention
can only be guessed at. Better yet, use a sensible loop:

if (count > 0) while (putchar(' ') && --count);

is exactly the same as

while (count > 0) {
    putchar(' ');
        --count;
}


Unless there's a reason to assume that count could also be < 0, this
would better be written as

while (count) {
    putchar(' ');
        --count;
}


> Another habit I have is to avoid a statement like:
>
>     if (abc == 42)

>
> and write it as
>
>     if (42 == abc)

>
> instead.


That's a habit of many people who either believe to be master yoda
('Your sister she is') or who believe their heart-felt support for
Nikolaus Wirth is so important that it trumps writing clear code.

    - compilers usually warn about = in conditions


        - this is an extremely uncommon error


        - the inversion doesn't help when both operands are l-values


So, program in Algol 60/ Pascal/ Modula/ Oberon or "take your := and
shove it". The world has moved on.