[swift-evolution] Switch statement using blocks for conditions

Xiaodi Wu xiaodi.wu at gmail.com
Fri Dec 23 10:35:10 CST 2016


Hi Marco,

This idea has already been discussed on this list; however, source-breaking
changes require "extreme" justification and this particular idea has not
been found to provide obvious benefit. Moreover, Swift cases allow
fallthrough, which is less explicable when you surround each case with
braces.

The focus of this phase of Swift Evolution is listed on the GitHub site and
is generally clustered around ABI stability and completing generics.

Cheers,

Xiaodi
On Fri, Dec 23, 2016 at 07:04 Marco Scannadinari via swift-evolution <
swift-evolution at swift.org> wrote:

> Hi,
>
> I found it odd that the `label:` style is used for switch-case conditions,
> considering that Swift does not have implicit fallthrough. To me the label
> style only makes sense if you think of conditions essentially as labels for
> a goto statement, which implies fallthrough.
>
> Personally I think this syntax would make more sense:
>
> switch condition {
>   case 1 {
>     //
>   }
>
>   case 2 {
>     //
>   }
> }
>
> This is how Rust implements match, although it is an expression so it
> especially applies to that context. Nonetheless I think the above syntax
> not only looks a lot nicer but makes more sense, especially since the
> current syntax is the only instance where Python-style colons and
> indentation are used for designating sections of code rather than braces.
>
> Thoughts?
>
> -Marco
> _______________________________________________
> 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/20161223/596dd926/attachment.html>


More information about the swift-evolution mailing list