Sujet : Re: Which code style do you prefer the most?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 05. Mar 2025, 05:46:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vq8kul$29gdt$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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