[swift-evolution] Remove default case in switch-case

Jacob Bandes-Storch jtbandes at gmail.com
Wed Dec 9 17:07:45 CST 2015


Sounds like the team/community has already shown that similarity with C
isn't a priority that overrides clarity/simplicity in the language. Thus, +1

On Wed, Dec 9, 2015 at 3:06 PM, Chris Lattner via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On Dec 9, 2015, at 3:01 PM, Mustafa Yusuf via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>
> Hello all. In switch statements in swift if all the possible cases aren't
> covered we have to supply a default case.
>
>     let number = 10
>
>     switch number {
>     case 10: print("yay")
>     case 12: print("close")
>     default: print("try again")
>     }
>
> My proposal is replace it with the "case _:".
>
>     let number = 10
>
>     switch number {
>     case 10: print("yay")
>     case 12: print("close")
>     case _: print("try again")
>     }
>
> Since underscore in swift means "whatever I don't care" it suits here
> better than "default". Correct me If I am wrong but this is the only use
> for "default" keyword in swift I guess. So we can completely remove
> "default" keyword from the language.
>
>
> FWIW, this is already supported.  We *also* support default for clarity of
> code / because it reads better, and for similarly with the (extended) C
> family of languages.
>
> -Chris
>
>
> _______________________________________________
> 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/20151209/8ac35d90/attachment.html>


More information about the swift-evolution mailing list