Deutsch   English   Français   Italiano  
<vq8kul$29gdt$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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: Which code style do you prefer the most?
Date: Wed, 5 Mar 2025 05:46:12 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <vq8kul$29gdt$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 05 Mar 2025 05:46:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="c7b28c7b2c5da4ab81c18f27a162cf8b";
	logging-data="2408893"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+OUocoOJZLQT+p1xneuHm+"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
Cancel-Lock: sha1:PyuaviiUGm4fLy4unXOgEkeG/kc=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vq7u5u$21gol$2@dont-email.me>
Bytes: 2665

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();
  }

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