[swift-evolution] Dotless case names in switch cases

Charles Srstka cocoadev at charlessoft.com
Sat Jan 16 18:05:21 CST 2016


> On Jan 16, 2016, at 1:20 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Definitely, Rob Rix has run into this problem in the wild too. I think that's a general ergonomic problem with our pattern syntax, though; 'let' on every pattern variable is verbose, and it's tempting when doing heavy pattern matching to reflexively type 'case let' at the start of every match to avoid it.

That could be fixed by getting rid of “case let”, though, and just putting the “let” next to the actual variable name:

case .Foo(let bar):

instead of:

case let .Foo(bar):

It seems a little more consistent with Swift’s type system in general, and it actually works today (at least, it did in the playground I just tried it in). And since it’s entered at the same time as you’re entering a variable name into the parens, it’s less likely to provoke that “argh, I forgot to put the left bracket on my Objective-C method” feeling that could cause one to reflexively type “case let” in the first place.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160116/1340274f/attachment.html>


More information about the swift-evolution mailing list