[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: formatting ?: operator
From: |
Rik |
Subject: |
Re: formatting ?: operator |
Date: |
Tue, 25 Apr 2017 09:35:17 -0700 |
On 04/25/2017 09:19 AM, John W. Eaton wrote:
> 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.
>
Alas, I just do it by hand. I checked to see what astyle would do, but it
just aligns the next line to the indent after the '=' sign.
--Rik
- formatting ?: operator, John W. Eaton, 2017/04/25
- Re: formatting ?: operator, Mike Miller, 2017/04/25
- Re: formatting ?: operator, John W. Eaton, 2017/04/25
- Re: formatting ?: operator, Rik, 2017/04/25
- Re: formatting ?: operator, John W. Eaton, 2017/04/25
- Re: formatting ?: operator, Mike Miller, 2017/04/25
- Re: formatting ?: operator, Rik, 2017/04/26