[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: formatting ?: operator
From: |
Mike Miller |
Subject: |
Re: formatting ?: operator |
Date: |
Tue, 25 Apr 2017 09:34:03 -0700 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Tue, Apr 25, 2017 at 12:19:59 -0400, 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.
In my vim configuration, when I start a new line after
"some_other_longer_condition", it auto-indents 2 × shiftwidth, so twice
the indentation level normally applied to a block indent, from the start
of the previous line.
There is a vim configuration option to auto-indent to the next character
after the previous unclosed parenthesis, which I have not bothered
enabling personally, but that would handle the above style
automatically.
I have also not bothered enabling GNU indenting style in my vim
settings, so I usually end up manually fixing the indent for single-line
vs brace-enclosed blocks.
--
mike
- 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