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

David Waite david at alkaline-solutions.com
Sun Jan 24 21:11:10 CST 2016

> 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.

In the case of a function parameter, it looks like it is a modifier of the signature, not an internal behavior of the function. Compare:

func foo(var a:String) { }
func bar(inout a:String) { }

This is why I personally recommended earlier in the thread proposing an alternative than a reversal - disallowing the current syntax increases clarity at the expense of terseness, which is one of fundamental design decision driving Swift. If someone has an alternative that increases clarity and terseness together when compared to SE-0003, they will have a much easier time.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160124/57c1c808/attachment.html>

More information about the swift-evolution mailing list