[swift-evolution] ternary operator ?: suggestion

Matthew Johnson matthew at anandabits.com
Sun Dec 6 19:15:26 CST 2015


I also agree with this.  I see no value in different syntax for statements and expressions, just unnecessary complexity.

Modifying the current syntax is an orthogonal issue.  If anyone feels the current switch syntax is to verbose I would recommend writing a new proposal to change it.  If such a proposal were adopted the new syntax should be used for both statements and expressions.

Sent from my iPhone

> On Dec 6, 2015, at 4:14 PM, Alex Lew via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 👍
> 
>> On Sun, Dec 6, 2015 at 5:12 PM, thorsten at portableinnovations.de <thorsten at portableinnovations.de> wrote:
>> Absolutely. Just the same rule: parts that were statements must be expressions. The else clause becomes mandatory.
>> 
>> -Thorsten 
>> 
>>> Am 06.12.2015 um 22:52 schrieb Alex Lew <alexl.mail+swift at gmail.com>:
>>> 
>>> I agree that it's simplest to just reuse switch keyword, and keep braces. +1.  
>>> 
>>> Would you allow the same thing with if?
>>> 
>>> let thisColor = if condition { .Red } else { .Blue }
>>> 
>>>> On Sun, Dec 6, 2015 at 4:44 PM, Rudolf Adamkovic <salutis at me.com> wrote:
>>>> > On 06 Dec 2015, at 22:35, thorsten--- via swift-evolution <swift-evolution at swift.org> wrote:
>>>> 
>>>> >
>>>> > I would prefer the expression to match the statement. The only difference would be that all parts that were statements now have to be expressions.
>>>> 
>>>> +1
>>>> 
>>>> >
>>>> > Therefore the switch-expression should simply look like follows:
>>>> >
>>>> > let thisColor = switch thatColor {
>>>> >         case .Red: .Green // must be an expression
>>>> >         default: .Yellow      // must be an expression
>>>> >     }
>>>> >
>>>> > No returns needed in the case clauses.
>>>> 
>>>> This actually looks great. One simple rule and zero new keywords.
>>>> 
>>>> Readable and simple to learn.
>>>> 
>>>> Fantastic!
>>>> 
>>>> > Formatting this as a one-liner would just require adding semicolons (though I wouldn't recommend this).
>>>> >
>>>> > -Thorsten
>>>> > _______________________________________________
>>>> > swift-evolution mailing list
>>>> > swift-evolution at swift.org
>>>> > https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/5e6ab41e/attachment.html>


More information about the swift-evolution mailing list