[swift-evolution] [Idea] Wrap switch cases in curly braces

G B g.c.b.at.work at gmail.com
Thu Jul 7 15:07:06 CDT 2016

It has always seemed odd to me that `case`s use a colon as a delimiter rather than curly braces like everything else.  Is there a reason for this other than the legacy of C-like languages?  

If I wanted to write a series of branching `if` \ `else` statements I would do it like so:

if x==0      { print(0) }
else if x==1 { print (1) }
else if x==2 { print(2) }
else         { print("other”) }

I believe all flow control is wrapped in curly braces, except for `case`s inside a `switch`:

switch x {
case 0: print(0)
case 1: print(1)
case 2: print(2)
default: print("other")

I feel like this would be more consistent with the rest of the syntax:

switch x {
case 0 { print(0) }
case 1 { print(1) }
case 2 { print(2) }
default { print("other”) }

The colon syntax evokes a label, but the modern, complex `case` statements in Swift don’t act much like labels.

More information about the swift-evolution mailing list