Sujet : Re: Which code style do you prefer the most?
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 26. Feb 2025, 21:09:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpnsd7$2n8td$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Mozilla Thunderbird
On 26/02/2025 17:47, Janis Papanagnou wrote:
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.
The difference is that the mistake :
if (flag)
doThis();
doThat();
really does happen in actual released code, and has caused significant problems. And if you have mixed tabs and spaces in the code, it is entirely possible that with different editors with different tab sizes, the code appears differently - adding to the confusion and the likelihood of errors going unnoticed.
Mistakes like "if (a = 42)" rarely make it past initial testing, and most compilers have warned about such errors for decades. (Some compiles - including modern gcc and clang - can spot the confusing indentation. But that has not been the case for so long.)