[swift-evolution] Proposal Sketch: simplify optional unwrapping syntax

Kevin Wooten kdubb at me.com
Sat Dec 19 16:09:02 CST 2015


> On Dec 19, 2015, at 1:37 PM, ilya <ilya.nikokoshev at gmail.com> wrote:
> 
> I prefer 
> 
> if let vc = someInterestingViewConroller {
>   vc.doSomething()
> }
> 
> - Explicit is better than implicit
> - shadowing is bad 
> - now there's no ambiguity about how to change the original property. 
> 

Creating a less descriptive short name in place of usually more descriptive name, which is already used throughout your code, is not “more explicit”.  You’ve removed shadowing and instead created two separately name variables referring to the same value. You’ve created _more_ ambiguity, not less.

Also, for 1 line blocks of code, “vc” might be ok but blocks 20 lines long that contain other contrived names, just to remove shadowing, (e.g. “vc2”, using your example) is only going to make it worse.

> Therefore I'm -1 on any proposal that hides explicit name binding and/or increases shadowing, including let foo and unwrap foo. 
> 
> On Sat, Dec 19, 2015 at 21:31 Kevin Wooten via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> As much fun as it to example with foo, I would argue the opposite when you use some real world variable names:
> 
> if let someInterestingViewConroller = someInterestingViewConroller {
> }
> 
> vs
> 
> If let someInterestingViewConroller {
> }
> 
> We know what let does and it should be enough to impart the necessary information for this statement.
> 
> When it comes to newcomers I think you'd be hard pressed to find somebody who'd be able to understand either form without teaching; so not losing much there.
> 
> 
> On Dec 19, 2015, at 10:01 AM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> 
>>> On Dec 11, 2015, at 8:19 AM, Jeff Kelley via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> I’ve had similar ideas to this. Instead of ditching the if let syntax altogether, another approach would be to use the existing name if no new name is given, so that this code:
>>> 
>>> 	if let foo = foo { /* use foo */ }
>>> 
>>> could become this code:
>>> 
>>> 	if let foo { /* use foo */ }
>>> 
>>> In both cases, foo is non-optional inside the braces. If you gave it another name with the if let syntax, that would work as it does today.
>> 
>> Hi Jeff,
>> 
>> This is commonly requested - the problem is that while it does help reduce boilerplate, it runs counter to the goal of improving clarity.
>> 
>> -Chris
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151219/3c86ce41/attachment-0001.html>


More information about the swift-evolution mailing list