Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: how to make a macro work as a single line if stmt without braces Date: Fri, 27 Sep 2024 01:43:34 -0700 Organization: A noiseless patient Spider Lines: 59 Message-ID: <86ldzd5vwp.fsf@linuxsc.com> References: <20240922080605.59@kylheku.com> <20240922192726.000061fc@yahoo.com> <86ikul6ruw.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 27 Sep 2024 10:43:34 +0200 (CEST) Injection-Info: dont-email.me; posting-host="abc45fc1b62a735d371ae748216349f9"; logging-data="713102"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iXNbqMxYsbeB9cx2A43xljWoPUrDYB/I=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:iRzBk1mLdWMBCz1tTEUC3MEZ34c= sha1:PbDd+eoK36qSJ95lN4lFoI97MEM= Bytes: 3042 Andrey Tarasevich writes: > 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 ==". Don't be silly, of course they are different. There is nothing artificial about surrounding controlled statements with braces. And writing braceless single-line if()s in cases where there is only a single controlled statement is something I was already doing - I didn't adopt it as a reaction to something that happened with multi-line if()s. > 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. Your view is contradicted by objective reality. > 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`. I think you need to learn the difference between a statement of opinion and a statement of fact. > 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. Making a false statement twice doesn't make it true.