Swift's "switch" syntax is confusing and should be replaced

Originator:kristopherdjohnson
Number:rdar://19320684 Date Originated:21-Dec-2014 10:42 AM
Status:Closed Resolved:Works as intended
Product:Developer Tools Product Version:6.1.1 (6A2008a)
Classification:UI/Usability Reproducible:Not applicable
 
Summary:
Swift provides a "switch" statement that is superficially similar to the switch statement provided by C and C++. However, it does not work the same way that C/C++ switch works, and its syntax is inconsistent with the general patterns of other Swift syntax.

C's switch statement is essentially a computed-goto statement, so it makes sense that its cases look like C goto labels. Further, C's switch supports fall-through from one case to the next, which is useful for its problem domain (low-level OS implementation).

However, Swift supports neither gotos nor fall-through, so the goto-like syntax is just confusing.

Each case in a Swift switch has its own variable scope. This is not obvious, because programmers expect braces around scopes.

A syntax like this would make more sense:

    switch x {
        case .SomeValue { ... }
        case .OtherValue, .ThirdValue { ... }
        default: { ... }
    }

Steps to Reproduce:
N/A

Expected Results:
N/A

Actual Results:
N/A

Version:
6.1.1 (6A2008a)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!