[swift-evolution] ternary operator ?: suggestion
clattner at apple.com
Tue Dec 15 15:35:37 CST 2015
> On Dec 15, 2015, at 8:32 AM, Dennis Lysenko via swift-evolution <swift-evolution at swift.org> wrote:
> I hate to triple-post, but removing ternary seems similar to the 'removing c-style for loops' proposal that was recently accepted: https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md <https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md>
> To quote:
> The C-style for-loop appears to be a mechanical carry-over from C rather than a genuinely Swift-specific construct. It is rarely used and not very Swift-like.
> You could say the same thing about ternary. Rarely used; not very Swift-like, conflicting with the use of ? 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.
There are significant differences though: C style for loop is almost never used (and many people chimed in to say that they had *zero* uses in their code), but ternary is widely used. In order to remove ternary, we’d need to have something to replace it with, which is the topic of much of this thread. IMO, in order to consider removing ternary, we’d have to introduce something that is *better* than the current ternary operator first.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution