[swift-evolution] About "default" keyword in switch statement

Joe Groff jgroff at apple.com
Tue Dec 6 19:38:59 CST 2016


> On Dec 6, 2016, at 3:48 PM, Robert Widmann via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Perhaps you're thinking about this choice of syntax from a different angle than was intended.  `default` is not literally meant to be a "default value" or, in most cases, "the default case", rather a "default pattern"; a place for control to flow given no other option.  Some other languages, especially those that emphasize patterns, syntaxize words like "otherwise" or simply use "_", but I've not seen languages that mix C-style switch-case keywords with C-style branching keywords before.

"Case Else" is common in Pascal-lineage syntaxes. (Shameless plug) We also used 'else' for the default block signifier in Clay, since we adopted block syntax for cases instead of label-style cases as in C, e.g. 'switch (x) case (1) { ... } else { ... }'.

-Joe




More information about the swift-evolution mailing list