Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: vallor Newsgroups: comp.lang.c Subject: Re: Which code style do you prefer the most? Date: Wed, 5 Mar 2025 07:02:46 -0000 (UTC) Organization: A noiseless patient Spider Lines: 70 Message-ID: References: <20250304175602.c9fe683d678d3a2ed101a4ac@g{oogle}mail.com> <20250304101022.154@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 05 Mar 2025 08:02:46 +0100 (CET) Injection-Info: dont-email.me; posting-host="22adc1313ef95ba9e464062a10f5f982"; logging-data="2440213"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OwnWJwIZvxkgun963fd4a" User-Agent: Pan/0.162 (Hmm4; 0a913ba3; Linux-6.14.0-rc5) Cancel-Lock: sha1:XKZ6CkXATEuaUAsaau1EzKBxsd4= X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9 wrote in : > On 04.03.2025 23:17, Richard Heathfield wrote: >> On 04/03/2025 21:49, Richard Harnden wrote: >>> >>> How do people format long and complex conditions, given that you're >>> trying not to a much over 80 columns? > > I had a look into that "C" project where I posted some excerpts but > unfortunately it hasn't code that's artificially split; I seem to avoid > overly complex expressions in the first place. > > BTW, one way to avoid complex expressions is to use interim variables > (if possible for semantical parts). (This had previously already been > suggested by someone else here some time ago). > > >> I like to break after a binary operator so that it is syntactically >> obvious that the line must continue: > > In principle I do the same. - But in cases like this: > > >> if((a != b && >> c != d && >> e != f) || >> (g = h() * i() && >> (j = k)) >> { >> foo(); >> } > > I prefer a logical bundling (and also try not to put '||' and '&&' in > the same category); something like > > if ((a != b && c != d && e != f) || > (g = h() * i() && (j = k))) // assuming assignments here > { > foo(); > } It may forever label me as a pariah, but if I were writing this for myself, I'd probably put it: if ( (a != b && c != d && e != f) || (g = h() * i() && (j = k) ) { foo(); } However, my C foo is not what it used to be. (Indeed, part of me wants to indent the braces around "foo()", but that would make it look ugly(er).) > > and, depending on the expression complexity, occasionally adding some > more spaces, like > > if ((a != b && c != d && e != f) || > > to easier identify the components (relational first, logical later). > > Janis -- -Scott