octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: formatting ?: operator


From: John W. Eaton
Subject: Re: formatting ?: operator
Date: Tue, 25 Apr 2017 12:19:59 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 04/25/2017 12:02 PM, Rik wrote:

I really like having the '?' and ':' line up vertically to show that there
is alternative A and alternative B.

I agree, which is why I might write

  retval = (lower
            ? octave::math::gammainc (x, a)
            : 1.0 - octave::math::gammainc (x, a));

even if the condition and the first expression will fit on a single line.

It seems verbose to wrap both the
entire line and the test condition in parentheses, but I'm not strongly
opposed if you want to use that convention.

It's not necessary to wrap the condition. My example could have been written this way:

   x = (some_long_condition || some_other_longer_condition
        ? some + expression - that / is * not + short
        : another + expression - that / is * also + not - short);

I'm curious to know whether you have to do the alignment by hand or if your editor (vim?) does it for you automatically.

jwe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]