Deutsch   English   Français   Italiano  
<vculjh$386eb$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: how to make a macro work as a single line if stmt without braces
Date: Tue, 24 Sep 2024 17:24:32 +0200
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <vculjh$386eb$1@dont-email.me>
References: <PaWdnZ3R-9zI6nP7nZ2dnZfqn_GdnZ2d@brightview.co.uk>
 <vcm16e$1hm2u$1@dont-email.me> <vcn6m8$1n1vu$1@dont-email.me>
 <vcp0rq$26p7b$1@dont-email.me> <20240922080605.59@kylheku.com>
 <vcpeo0$28shf$1@dont-email.me> <20240922192726.000061fc@yahoo.com>
 <86ikul6ruw.fsf@linuxsc.com> <vcujmj$384dh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 24 Sep 2024 17:24:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="295059a1925683a809cfd14e600ca3af";
	logging-data="3414475"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX190ZVRjTxeBBUro6K53vL40YclU6Ht+/Kg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:XPzpYnriBoXIEZwRPDug0wkF7/Y=
Content-Language: en-GB
In-Reply-To: <vcujmj$384dh$1@dont-email.me>
Bytes: 3289

On 24/09/2024 16:52, Andrey Tarasevich wrote:
> On 09/24/24 7:36 AM, Tim Rentsch wrote:
>>
>> 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.
>>
> 
> It is just weird.
> 
> 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.

They do.

You might not do so, but other people do.  Not often, but still too often.

(I don't think Yoda conditions are the answer here - automatic checking 
from tools is simple enough.)

> 
> 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. People just don't 
> make this mistake.
> 

Again, people do.

I gave you a link earlier to a hugely costly example of this mistake, 
made by very experienced C programmers.

But I am confident that Tim, and others (like me) who use a similar 
style, are almost entirely immune to this particular mistake.

Now, if there were a good way to automatically detect mixups between & 
and &&, | and ||, then we'd be rid of a number of these kinds of errors 
in C coding.