| Deutsch English Français Italiano |
|
<vcn997$1nfpt$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: how to make a macro work as a single line if stmt without braces
Date: Sat, 21 Sep 2024 21:11:21 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <vcn997$1nfpt$1@dont-email.me>
References: <PaWdnZ3R-9zI6nP7nZ2dnZfqn_GdnZ2d@brightview.co.uk>
<vcm16e$1hm2u$1@dont-email.me> <vcn6m8$1n1vu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 21 Sep 2024 22:11:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e721e00107fc1cc5a0da1c4653c9f2db";
logging-data="1818429"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EpzvzPqNo8pm1fs3wZjWX"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:hY7tzuACsItp+c9E1N5EaMULHho=
In-Reply-To: <vcn6m8$1n1vu$1@dont-email.me>
Content-Language: en-GB
Bytes: 3063
On 21/09/2024 20:27, Andrey Tarasevich wrote:
> On 09/21/24 1:47 AM, David Brown wrote:
>>
>> You should get in the habit of being consistent with braces, and being
>> generous with them. Your future self with thank you.
>>
>> if (failed) {
>> WARN("failed because...");
>> } else {
>> ok++;
>> }
>>
>
> Nope. There's absolutely no reason to overuse braces.
>
> And don't use "Egyptian" braces. The latter is actually an ill-begotten
> attempt to remedy the damage from the former. Just stop overusing
> braces, and there'll be no need for the remedy. Easy.
>
> This is the proper formatting style with braces
>
> if (failed)
> {
> ...
> }
> else
> {
> ...
> }
>
> The vertical spacing introduced by the `{` line provides separation
> between condition and the branch,
Have a look at the middle of that example:
} else {
Here the braces serve no purpose; you already have 'else' separating the
two branches to which you can add extra vertical space if you like.
This is not just because of braces, you get the same thing with:
end else begin
Both are symptoms of the idea that any branch can only have a single
statement, and if you need more, than you need a compound statement
using {s1; s2; s3;} (unless you're Tim then you use s1, s2, s3 which may
or may not work and is probably the worst of all).
Since this is C, then if braces are to be mandatory, then at least allow
people to write their code a little more compactly if they wish. In a
language that allows proper statement sequences, you wouldn't commonly
see this:
if failed then
s1
else
s2
...
But this exactly how you are suggesting C should be written, when
looking purely at the content: 50% blank lines.
It looks ridiculous and those statements look very lonely!