Liste des Groupes | Revenir à cl c |
On 09/24/24 7:36 AM, Tim Rentsch wrote:Well, it is the ONLY way C provides to write the branches of an if-statement. Each only takes a single statement.>It is just weird.
My long-standing habit is to write this
>
if(x) bar(x);
>
or this
>
if(x){
bar(x);
}
>
but never this
>
if(x)
bar(x);
>
The reason for this habit is that many years ago I got bitten by
trying to add a line in the last case. The habit subsequently
adopted has proven very effective at eliminating such errors.
>
This is no different from insisting in using "Yoda conditions", claiming that "many years ago I was bitten by an accidental = in place of ==". In reality we all know that regardless of how many scary stories someone might tell about dangers of accidental assignment in place of comparison, it just does not happen. There's no such issue. People just don't make this mistake.
The same applies to
if(x)
bar(x);
This is the right thing to do. It is the most readable and elegant way to write a simple `if`.
And the dreaded "one day you will add a line and suffer" just doesn't happen. There's no such issue.No, this must happen ALL THE TIME. That is, you write one statement, then decide you need more than one. Or you start with 3 statements and get rid of two of them.
People just don't make this mistake.And there is that too. Maybe YOU don't make it, in the same way that you probably know all the binary operator precedences by heart and never get them wrong. Well, not everyone is perfect.
Les messages affichés proviennent d'usenet.