Path: csiph.com!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: Sun, 29 Sep 2024 19:18:54 -0700 Organization: A noiseless patient Spider Lines: 71 Message-ID: <86seth28a9.fsf@linuxsc.com> References: <86frpk3s1u.fsf@linuxsc.com> <20240928203048.00006703@yahoo.com> <86v7yf2h8t.fsf@linuxsc.com> <20240929124835.00003ca2@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 30 Sep 2024 04:18:58 +0200 (CEST) Injection-Info: dont-email.me; posting-host="e153cd915235505af8c5be8b67e222a3"; logging-data="2193100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mqe0AakNtf69a2XANe3rPa+xHrPTgZ5U=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:jn+/fVxSBtWQgpG8rAjaDcyUZPw= sha1:XHlJYR1Jp1s5EvYAAlaCVlXRx98= Xref: csiph.com comp.lang.c:388563 Michael S writes: > On Sat, 28 Sep 2024 21:53:06 -0700 > Tim Rentsch wrote: > >> Michael S writes: >> >>> On Sat, 28 Sep 2024 05:02:05 -0700 >>> Tim Rentsch wrote: >>> >>>> Andrey Tarasevich writes: >>>> >>>> [...] >>>> >>>>> And don't use "Egyptian" braces [the style used in the >>>>> first edition of The C Programming Language, by Kernighan >>>>> and Ritchie]. >>>>> >>>>> 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, which makes >>>>> your code much more readable. [...] >>>> >>>> What qualities does this layout style have that make it "more >>>> readable", other than it being one that you like or prefer? >>> >>> { at the same level of indentation as its matching } >> >> Certainly it is true that the layout style shown has the open >> brace at the same level of indentation as the matching close >> brace. What about that property makes this layout "more >> readable"? The statement given sounds like a tautology - >> I don't see that any new information has been added. > > It makes it easier to see where block starts and where it ends. > Opening { followed by empty line is more bold visually than 'if > something { ' or then '} else {'. Certainly having an open brace on a line by itself stands out more than if the open brace were written at the end of an if() or while() line. Whether that makes it easier to see where a block starts is something that can be measured, and also might be reader dependent. For myself I find that having open braces on lines by themselves interferes with my ease of reading. And that has been true since before I ever programmed in C. > Now, I can live with both styles, but can see why many people > prefer style advocated by Andrey. I've made a serious effort over the years to find out why people who prefer the Andrey style are so definite that it is somehow better. I have yet to get an illuminating answer to that question. I've gotten various forms of non-answer arguments, and what seem to me to be circular answers (like saying it is more readable). I understand that they prefer it; I still don't understand why they prefer it. I acknowledge your point that they think the open brace on a line by itself somehow helps with their reading. But I still don't understand why they think that.