[swift-evolution] ternary operator ?: suggestion (swift-evolution Digest, Vol 1, Issue 181)

Rainer Brockerhoff rainer at brockerhoff.net
Tue Dec 15 12:35:55 CST 2015


On 12/15/15 14:32, Dennis Lysenko wrote:
> You could say the same thing about ternary. Rarely used;

I seem to use it _a lot_ in C and ObjC and find it more concise that
proposed alternatives. Especially the `?:` variety.

> not very Swift-like, conflicting with the use of ? for optionals;

That I don't see, as an isolated `?` with whitespace around is AFAIK not
used for optionals.

> seems to be disliked (rationally or irrationally) by many; and in
> almost all cases you can achieve the same exact thing, but ostensibly
> more readable, with a few extra lines.

But the objective is exactly to say whatever on a single line!

I grant that you should either not nest it, or always use ()s, but that
is true for all boolean operators IMHO.

-- 
Rainer Brockerhoff  <rainer at brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://brockerhoff.net/blog/


More information about the swift-evolution mailing list