[swift-evolution] Reconsidering SE-0003 Removing var from Function Parameters and Pattern Matching

Dave Abrahams dabrahams at apple.com
Sun Jan 24 23:33:01 CST 2016


on Sun Jan 24 2016, David Waite <david-AT-alkaline-solutions.com> wrote:

>> On Jan 24, 2016, at 6:44 PM, Charles Srstka via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>>> On Jan 24, 2016, at 12:31 PM, Dave Abrahams via swift-evolution
>>> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>
>
>>> wrote:
>>> 
>>> That's not the purpose; even though I am not a fan of prohibiting "var"
>>> there, I understand that the purpose of doing so is avoiding confusion,
>>> because some people believe they are getting a reference through which
>>> to mutate the contents of the original optional.
>> 
>> 
>> But that’s not what assigning something to a var means in any other
>> context. Why should it be any different here?
>> 
> In the case of "if let x = x { … }”, the shadowing/copying of the
> original value is not apparent - from the user perspective, the
> language just “knows” within the block to stop treating “x” like an
> optional.

That's one reason I'm not a fan of using the same identifier in both
places in these examples.  I've usually found the code to be a little
clearer anyway, when I take the time to find a different name.

FWIW-ly y'rs,

-- 
-Dave


More information about the swift-evolution mailing list