Sujet : Re: Which code style do you prefer the most?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 26. Feb 2025, 17:47:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpngiq$2l3cv$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 26.02.2025 17:26, Scott Lurndal wrote:
David Brown <david.brown@hesbynett.no> writes:
It is also an argument against writing code like :
>
if (flag)
doThis();
>
Not only is adding a "doThat();" error-prone in itself (forgetting to
add braces is a real risk), but it means adding (or later removing) a
single line is now a three-line change.
Agreed.
I consider that argument of about the same quality as the suggestion
to write
if (42 == a) instead of if (a == 42)
just to prevent the error of writing if (a = 42) in "C" (and
similar languages).
I don't think this is convincing.
But we are again going to (or still) discussing mainly preferences
than clear facts. (YMMV.)
And for those of us old enough, the lack of braces means
that the 'if (flag)' line may need to be repunched to add the opening
brace later...
The guys old enough to have punched cards - call me a member of this
group - will probably prefer to not write the opening brace on that
same line but open a new line for it, as in
if (flag)
{
doThis();
orThat();
}
Also, such a card needs no "re-punching"; just add the character to
the existing card. (Or did you mean that by "re-punching"? - In that
case it's also not convincing; it means you have to add unnecessary
cards, those with the braces, just for the possibility that the code
gets maybe changed later.)
Janis