The curse of knowledge. :)<div><br></div><div>I don't mind 'for var' to be gone or var in functions.</div><div>The suggestion of 'if bind' seems interesting but then I think it may become a little too magical. A combination of the two ideas would be something like:<br></div><div><br></div>let x:Int? = 1<div><div><br></div><div>if bind x {</div> var x = x</div><div> x += 2</div><div> methodWithSideEffets(x)</div><div><div>}</div><div><br></div>same as :</div><div><br></div><div>if let x = x {</div><div> var x = x</div><div> <font size="2"><span style="background-color:rgba(255,255,255,0)"> x += 2</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"> methodWithSideEffets(x)</span></font></div><div>}</div><div><br></div><div>vs</div><div><br></div>if var x = x {<div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"> x += 2</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"> methodWithSideEffets(x)</span></font></div></div><div><span></span>}<br><div><div><br></div><div><br>On Thursday, January 28, 2016, Jordan Rose <<a href="javascript:_e(%7B%7D,'cvml','jordan_rose@apple.com');" target="_blank">jordan_rose@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I <i>still</i> don't understand how value types and reference types are different here. Here's a contrived "confusion" example (but we have seen similar real-world code):</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>for var element in array {</div><div> if element.isNotUpToMyStandards {</div><div> element = makeANewElement()</div><div> // 'element' is not stored back into 'array', but was meant to be.</div><div> }</div><div>}</div></blockquote><div><br></div><div>This code, or rather the behavior the developer intended, is perfectly reasonable. But it's exactly the same code whether there's a value type or a reference type involved. I get that there are other examples where this is <i>not</i> the case, but I can't see how <i>those</i> would be any <i>less</i> confusing by adding this rule.</div><div><br></div><div>But maybe I'm just too familiar with Swift, and so have trouble putting myself in the shoes of a new learner.</div><div><br></div><div>Jordan</div><div><br></div><br><div><blockquote type="cite"><div>On Jan 27, 2016, at 20:45 , J. Cheyo Jimenez <<a>cheyo@masters3d.com</a>> wrote:</div><br><div><div dir="ltr"><div>R<span style="font-size:12.8px">eassigning of class objects probably occurs less than mutations of structs inside `if var` or `guard var`.</span><br></div><div><span style="font-size:12.8px">The main reason for the removal of </span><span style="font-size:12.8px">`if var` or `guard var`, AFAIK, is that people get confuse about references. Perhaps just limiting their use for value types could then clear up the confusion. </span></div><div><span style="font-size:12.8px">example of warning. </span></div><div><span style="color:rgb(80,0,80);background-color:rgba(255,255,255,0)">"'if var' is restricted to value types, did you mean 'if let'?"</span><br></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div>One of the issues is that now all comma separated optionals need to be value types or offer alternative syntax. </div><div><br></div><div>if var value1 = value1, ref1 = ref1 {} /// This would not work</div><div><br></div><div>if var value1 = value1, let ref1 = ref1 {} /// Possible solution, notice the `let`<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 27, 2016 at 8:05 PM, Jordan Rose <span dir="ltr"><<a>jordan_rose@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>That doesn't make sense to me. If it's sometimes necessary to reassign a struct containing a single reference, then surely it may be necessary to reassign a single reference not contained in a struct.</div><span><font color="#888888"><div><br></div><div>Jordan</div></font></span><div><div><br><div><blockquote type="cite"><div>On Jan 26, 2016, at 20:37 , Nate Birkholz via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="auto"><div>Seems in line with other compiler warnings.<br><br>Sent from my iPhone, please excuse brevity and errors</div><div><br>On Jan 26, 2016, at 8:30 PM, J. Cheyo Jimenez via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div>Would it be confusing if `guard var ` or `if var ` <span></span>was only allowed for value types? </div><br><div><br>On Tuesday, January 26, 2016, Dave Abrahams via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
on Tue Jan 26 2016, Tian Zhang <<a>swift-evolution@swift.org</a>> wrote:<br>
<br>
> I’m also curious how most people fix “guard var” or “if var”?<br>
> Especially for checking a class object for protocol conformation and<br>
> set variable on the object?<br>
><br>
> like in this case,<br>
><br>
>> if var vc = vc as? ControlPanelConfigurationProtocol {<br>
>> vc.servicePresentationObject = service<br>
>> vc.presentAsPanel = true<br>
>> }<br>
><br>
> become<br>
><br>
>> if let vc = vc as? ControlPanelConfigurationProtocol {<br>
>> var vc = vc<br>
>><br>
>> vc.servicePresentationObject = service<br>
>> vc.presentAsPanel = true<br>
>> }<br>
<br>
<br>
If vc has class type, you don't need the var at all.<br>
<br>
> I saw a few people suggest to create a method on the protocol like<br>
> “configureObject(...)” with all potential args and have the object to<br>
> figure it out but doing so I feel we’re losing the benefits offered by<br>
> property observation for the underlying object. Using pattern “if let”<br>
> with a “var” in the block just to make the property mutable again<br>
> feels really strange.<br>
><br>
> Best Wishes,<br>
> Tian<br>
>> An alternative would certainly be interesting but I would prefer to<br>
>> take it one step at a time and avoid being hasty so we can come up<br>
>> with something really great. What did most of your var fixes look<br>
>> like, by the way? Did you end up changing the layout of your value<br>
>> types or did you decide to add more vars?<br>
>><br>
>> David<br>
>><br>
>> > On Jan 24, 2016, at 7:19 PM, Zach Waldowski via swift-evolution<br>
>> > <swift-evolution at <a href="http://swift.org/" target="_blank">swift.org</a><br>
>> > <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>>> wrote:<br>
>> ><br>
>> > -1<br>
>> ><br>
>> > Having already adopted the syntax in my projects in anticipation of 2.2,<br>
>> > the increase in clarity at the expense of terseness is appreciated. A<br>
>> > proposal should not be discussing an alternative, not a rollback.<br>
>> ><br>
>> > Cheers!<br>
>> > Zachary Waldowski<br>
>> > zach at <a href="http://waldowski.me/" target="_blank">waldowski.me</a> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br>
>> ><br>
>> > On Fri, Jan 22, 2016, at 12:26 PM, David Farler via swift-evolution<br>
>> > wrote:<br>
>> >> Hello everyone,<br>
>> >><br>
>> >> I'd like to reconsider SE-0003 for Swift 3 and propose cancelling the<br>
>> >> change in its entirety. After collecting feedback since Swift's open<br>
>> >> source launch, I no longer feel this is a good move and there are a few<br>
>> >> reasons why.<br>
>> >><br>
>> >> There are two main patterns that the removal penalizes:<br>
>> >><br>
>> >> - Get-Modify-Reassign<br>
>> >> - Get-Modify-Return<br>
>> >><br>
>> >> I've found that many of the problems with this proposal stem from the<br>
>> >> uses before and after the "Modify" part, before returning or reassigning<br>
>> >> with the new value.<br>
>> >><br>
>> >> I've seen a few common responses to the var removal. Consider a<br>
>> >> `Rectangle` struct:<br>
>> >><br>
>> >><br>
>> >> struct Rectangle {<br>
>> >> var origin: (x: Double, y: Double)<br>
>> >> var size: (width: Double, height: Double)<br>
>> >> }<br>
>> >><br>
>> >><br>
>> >> Even with mutable variables `origin` and `size`, this pattern would be<br>
>> >> impossible:<br>
>> >><br>
>> >><br>
>> >> var selection = getRectangularSelection()<br>
>> >> if var rect = selection?.rect {<br>
>> >> // Mutate `rect` ...<br>
>> >> selection.rect = rect<br>
>> >> }<br>
>> >><br>
>> >><br>
>> >> So, one might shadow the variable, which is not ideal:<br>
>> >><br>
>> >><br>
>> >> var selection = getRectangularSelection()<br>
>> >> if let rect = selection?.rect {<br>
>> >> var rect = rect // Not so great<br>
>> >> // Mutate `rect` ...<br>
>> >> selection.rect = rect<br>
>> >> }<br>
>> >><br>
>> >><br>
>> >> Or, you might make a transformation function on `Rect`:<br>
>> >><br>
>> >><br>
>> >> struct Rectangle {<br>
>> >> var origin: (x: Double, y: Double)<br>
>> >> var size: (width: Double, height: Double)<br>
>> >> func withOrigin(x: Double, y: Double) -> Rect {<br>
>> >> var r = self<br>
>> >> r.origin = (x, y)<br>
>> >> return r<br>
>> >> }<br>
>> >> }<br>
>> >><br>
>> >><br>
>> >> This is a much better solution than shadowing but you would need one of<br>
>> >> these for any property that you want to mutate and I think you'll agree<br>
>> >> that it doesn't scale with the language we have today. This response begs<br>
>> >> for a kind of initializer that takes all of the fields of the original<br>
>> >> struct except any that you want to override:<br>
>> >><br>
>> >><br>
>> >> if let rect = selection?.rect.with(origin: newOrigin) {<br>
>> >> // ...<br>
>> >> }<br>
>> >><br>
>> >><br>
>> >> Straw syntax, but maybe you'll see something along these lines on<br>
>> >> swift-evolution in the future, which would provide a clear alternative to<br>
>> >> direct mutation patterns. Even then, I think having complementary<br>
>> >> patterns in the language isn't a bad thing.<br>
>> >><br>
>> >> These problems come up with the other variable bindings but the one that<br>
>> >> ended up bothering me the most was `guard var`:<br>
>> >><br>
>> >><br>
>> >> func transform(selection: Rect?) {<br>
>> >> guard let rect = selection else { return }<br>
>> >> var _rect = rect<br>
>> >> // Mutate `_rect` ...<br>
>> >> }<br>
>> >><br>
>> >><br>
>> >> One of the guard statement's main purposes is to conditionally bind a<br>
>> >> value as a peer in its own scope, not an inner scope like if statements.<br>
>> >> Not having var makes the guard statement much weaker.<br>
>> >><br>
>> >> There is certainly a bit of confusion about the nuances between value and<br>
>> >> reference semantics, who owns a value and when, how effects are<br>
>> >> propagated back to values, but I think we can attack the problem with<br>
>> >> more finesse.<br>
>> >><br>
>> >> Value types are one of the attractive features of Swift – because of<br>
>> >> their semantics, mutating algorithms are written in a familiar style but<br>
>> >> keeping effects limited to your unique reference. I don't think we should<br>
>> >> give that up now to address confusion about semantics, out of principle,<br>
>> >> or in anticipation of new language features. I propose cancelling this<br>
>> >> change for Swift 3 and continue to allow `var` in the grammar everywhere<br>
>> >> it occurs in Swift 2.2.<br>
>> >><br>
>> >> Regards,<br>
>> >> David<br>
>> >> _______________________________________________<br>
>> >> swift-evolution mailing list<br>
>> >> swift-evolution at <a href="http://swift.org/" target="_blank">swift.org</a> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br>
>> >> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>> >> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br>
>> > _______________________________________________<br>
>> > swift-evolution mailing list<br>
>> > swift-evolution at <a href="http://swift.org/" target="_blank">swift.org</a> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br>
>> > <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>> > <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a>swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
--<br>
-Dave<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a>swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div>_______________________________________________<br>swift-evolution mailing list<br><a>swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></blockquote></div><br></div>
</div></blockquote></div><br></div></blockquote></div>
</div></div>