[swift-evolution] Modernize Switch/Case Statements?

‫אביאל גרוס‬‎ avielgross at gmail.com
Sat Jan 30 08:07:52 CST 2016


I agree on the break and fallthrough points, I also think forcing curly braces would add unwanted complexity to simple switch blocks. Even worse - the way switch looks today it encourages clean and simple blocks, with short cases; adding curly braces might lead to huge switch cases which are impossible to follow…

> On Jan 30, 2016, at 2:03 PM, Andrew Bennett via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I like this idea, but I don't have enough detail to +1.
> 
> It would be good to show how all current switch behaviour would work.
> 
> How would 'break' and 'fallthrough' work?
> 
> It seems 'break' is redundant now.
> 
> Would the following code's 'break' act on the switch, or on the for loop?
> 
> for i in 0...5 {
>     switch i {
>         case 4 { break }
>         default { print(i) }
>     }
> }
> 
> On Saturday, 30 January 2016, Haravikk via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> I’d say to make it optional, as the use of just a colon is great for compact switch statements with short cases, so I think they’re worth retaining.
> 
> Actually, one thing we don’t have in Swift is the ability to just put blocks (curly braces) wherever we like, which in some languages is a useful tool for variable scope when you know you only need something for a short time, but might want to re-use the name. Currently they just result in a “trailing closure separated by multiple new-lines” warning, so they could perhaps be made available, in which event you could use them in larger case statements whenever you wished.
> 
>> On 29 Jan 2016, at 22:45, Rudolf Adamkovič via swift-evolution <swift-evolution at swift.org <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>> wrote:
>> 
>> +2 from me! One for curly braces and one for proper indentation.
>> 
>> R+
>> 
>>> On 28 Jan 2016, at 02:35, Joseph Essin via swift-evolution <swift-evolution at swift.org <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>> wrote:
>>> 
>>> As a budding iOS developer, I thought it might be nice if Swift were to further improve on C's switch statement by using curly brackets to denote a block instead of a colon. It seems like this would be more consistent with the language at large and make indention more intuitive.
>>> 
>>> Here's a quick example of what it might be.
>>> 
>>> switch value {
>>>   case expression {
>>>   }
>>> }
>>> 
>>> I apologize if this message isn't in the right format--I've not used a mailing list before.
>>> 
>>> Joseph Essin
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <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/20160130/5f59052e/attachment.html>


More information about the swift-evolution mailing list