[swift-evolution] ternary operator ?: suggestion

David Hart david at hartbit.com
Sat Dec 5 13:40:43 CST 2015


> This is subtle and requires thought

What do you envision as the pitfalls of the design thinking behind if/switch expressions? I’m not a compiler programmer, but a prog-lang enthusiast. I wouldn’t mind a little nudge in the right direction.

David.

> On 05 Dec 2015, at 18:09, Chris Lattner <clattner at apple.com> wrote:
> 
> 
>> On Dec 4, 2015, at 11:43 AM, J. Cheyo Jimenez <cheyo at masters3d.com <mailto:cheyo at masters3d.com>> wrote:
>> 
>> I'd like some feedback from the core team to see if eliminating the ternary operator and replacing it with if-else is even proposal worthy. 
>> 
>> Some interesting code in the standard library that uses the ternary operator quite a bit. 
>> 
>> https://gist.github.com/masters3d/7b0c6f3653368afe4357 <https://gist.github.com/masters3d/7b0c6f3653368afe4357>
> 
> FWIW, I have no love for the ternary operator (it is totally "bizarre C magic”), but it does solve a problem that Swift currently otherwise has no solution for.
> 
> If you’re interested in pursuing this, then the right path forward is to build a holistic proposal to turn statements (like if and switch) into expressions.  This is subtle and requires thought, but is widely desired and if someone were interested in driving the design and implementation, then I’d be interested to see it happen.
> 
> -Chris
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151205/4bbc13a2/attachment.html>


More information about the swift-evolution mailing list