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

Roth Michaels roth at rothmichaels.us
Thu Jul 7 15:31:28 CDT 2016

On Thu, Jul 07 2016 at 04:07:06 PM, G B via swift-evolution <swift-evolution at swift.org> wrote:
> 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.

I sort of see what you are saying about `case` not seeming like a label
since we don't have GOTO in Swift.

I prefer the colon vs your brace suggestion, because from my
perspective, the `switch` expression is the control flow statement and
to the cases are like some sort of label even if they include complex
pattern matching.

While Scala drops the colon to avoid case statements looks like labels,
but uses => instead of whitespace and {} --- I prefer this to your
suggestion, but as I said also think the colon is fine.

Roth Michaels
roth at rothmichaels.us

More information about the swift-evolution mailing list