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, 09:35:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vq92c7$2bdt3$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 05.03.2025 08:02, vallor wrote:
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)
)
Why "pariah"?
That looks (while maybe not prevalent) quite clear and sensible.
It hasn't prevented you from a missing parenthesis, though. ;-)
There's a reason why I dislike languages whose syntax is cluttered
with parentheses, compared to (for example)
IF a /= b AND c /= d AND e /= f
OR
g = h * i AND j = k
THEN
(Note that this code is not equivalent to the "C" code (assignment
vs. equality test)[*]. It should just illustrate what it means if all
those spurious parenthesis are omitted from a language. Of course
you can also add parenthesis around the 'AND' expressions to make
things clear. But 'if' or functions without parameters don't need
parenthesis [in other non-"C"-like languages].)
Janis
[*] The sample based on Algol 68 doesn't treat an 'int' as a 'bool'.
So functionally more equivalent something like this may be given
IF a /= b AND c /= d AND e /= f
OR
(g := h * i; g /= 0) AND (j := k; j)
assuming j, k be bools, or (j := k; j != 0) if they are ints.
Pascal has a similar parenthesis-free syntax concerning the control
constructs and parameterless functions, but (surprisingly) they had
decided to have relational expressions written in parenthesis in
such contexts: (a <> b) AND (c <> d) AND (e <> f)
{
foo();
}
[...]