Deutsch   English   Français   Italiano  
<vq8sul$2af0l$1@dont-email.me>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: vallor <vallor@cultnix.org>
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: <vq8sul$2af0l$1@dont-email.me>
References: <vpkmq0$21php$1@dont-email.me>
	<20250304175602.c9fe683d678d3a2ed101a4ac@g{oogle}mail.com>
	<vq75k8$1t6ut$2@dont-email.me> <vq785i$1u7v7$1@dont-email.me>
	<20250304101022.154@kylheku.com> <vq7shq$226p3$1@dont-email.me>
	<vq7u5u$21gol$2@dont-email.me> <vq8kul$29gdt$1@dont-email.me>
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<Q#U*4QO)$l81M`{Q/n
 XL'`91kd%N::LG:=*\35JS0prp\VJN^<s"b#bff@fA7]5lJA.jn,x_d%Md$,{.EZ
Bytes: 3312

On Wed, 5 Mar 2025 05:46:12 +0100, Janis Papanagnou
<janis_papanagnou+ng@hotmail.com> wrote in <vq8kul$29gdt$1@dont-email.me>:

> 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