<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+1 also for the proposal.<div class=""><br class=""></div><div class="">It might even be clearer than the actual behavior.</div><div class=""><br class=""><div class="">
<div class="">Pierre</div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 16 déc. 2015 à 09:05, ilya via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: pre-wrap;" class="">+1 explicit is better than implicit (capture of self) <br class=""><br class="">This should also be promoted by style guides. It's easy for a novice to miss that self.property captures the whole self, the capture list is much more useful in that regard. <br class=""></div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="ltr" class="">On Wed, Dec 16, 2015 at 05:06 Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class="">I believe it has been made clear upthread now, but only the closure is capturing self.&nbsp; Your evil function only stores a copy of the dictionary. &nbsp;</div><div class=""><br class=""></div><div class="">This behavior is identical whether you use [strong self] and metadata or you use self.metadata so I don’t understand why it would be an argument against the proposal.&nbsp; Either way the capture of self by the closure is explicitly represented in the code where it happens. &nbsp;[strong self] actually seems a bit more clear to me.</div><div class=""><br class=""></div><div class="">An example that behaves like you stated could be concocted if we modify your example to pass a bound method rather than a property value, however that seems pretty unlikely to happen unintentionally even if / when we can obtain references to bound property getters / setters.</div><div class=""><br class=""></div><div class=""></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class=""><span style="font-family: HelveticaNeue;" class="">typealias&nbsp;evilArg = [String:String]</span></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class="">var&nbsp;strongReference: () -&gt; evilArg<br class="">func&nbsp;evil(foo: () -&gt; evilArg&nbsp;) {<br class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>strongReference&nbsp;= foo<br class=""><div class=""><div style="word-wrap: break-word;" class=""><div class="">}</div><div class=""><br class=""></div><div class=""></div></div></div></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class=""><div style="word-wrap: break-word;" class=""><div class="">final&nbsp;class&nbsp;Photo {<br class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>var&nbsp;data = [UInt8](count: 100000000, repeatedValue: 0)&nbsp;//a large amount of data<br class=""></div></div></div></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class=""><div style="word-wrap: break-word;" class=""><div class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>func metadata() -&gt; [String:&nbsp;String] { return [:] }</div></div></div></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class=""><div style="word-wrap: break-word;" class=""><div class=""><br class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>func&nbsp;save() {<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>evil(self.metadata)<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>}<br class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>}<br class=""><div class=""><div style="word-wrap: break-word;" class=""><div class="">}</div></div></div></div></div></div></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class=""><div style="word-wrap: break-word;" class=""><div class=""></div></div></div></div></div><div class=""><br class=""></div><div class="">I understand why you’re afraid of anything that might lead to unintentionally storing a strong reference or creating a reference cycle.&nbsp; I don’t understand why this proposal is likely to make that happen.&nbsp; I would even argue it might make it less likely to happen.&nbsp; If developers get in the habit of using the capture list rather than explicitly using “self.” in the body they will be more likely to capture only what they need.&nbsp; In your example the developer may have specified [metadata = self.metadata] rather than using [strong self] if the metadata value at the time of closure capture was sufficient.</div></div><div style="word-wrap: break-word;" class=""><div class=""><br class=""></div><div class="">Matthew</div></div><div style="word-wrap: break-word;" class=""><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 7:23 PM, Drew Crawford via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap: break-word;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 7:15 PM, Greg Parker &lt;<a href="mailto:gparker@apple.com" target="_blank" class="">gparker@apple.com</a>&gt; wrote:</div><br class=""><div class=""><span style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">We could make it more difficult for unaware programmers to *write* the `[strong self]` version, at least. When a programmer writes just `metadata` in a closure, the compiler could continue to suggest using `self.metadata` and not suggest using `[strong self]`.</span></div></blockquote></div><br class=""><div class="">That's not (especially) the danger I'm worried about.</div><div class=""><br class=""></div><div class="">I'm worried about the case where I write `[strong self] in` and then years later I add the `evil(f)` to the bottom of the closure, because it turns out we need more code in there.</div><div class=""><br class=""></div><div class="">I'm also worried about the case where I write nonEvil(f) but at some later time the implementation of nonEvil(f) becomes evil.</div><div class=""><br class=""></div><div class="">I'm also worried about the case where nonEvil(f) is a call into closed-source UIKit and without any visibility to me, UIKit's implementation of nonEvil becomes evil between iOS10b3 and iOS10b4.</div><div class=""><br class=""></div><div class="">These things are "category 5" bugs waiting to happen, and they can't be competently addressed with a UI-level fix in Xcode.</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAcWRvrKJiA0Q-2FRIpXY8-2B503kAOGN-2B9XG2PlniO9WFb2Q7QEqJVC04Bo5Ogu5HSavR-2FkXcnfJ3VP1CpB7uYILkfTQ3cMXUMYveFmskLKIiZg5A0eYsQvB-2BpT2i8593bus-2Fem0QOkd23pkhmoGsw4VPDpYAm1-2FrpPLdGAuw1cLJAaFIWCGpWuAW5HmC6vKdAL-2Fqs-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54MNh1VMcq1gEkchtcNCD0P6nwRqQoa6XUtMNu86XI5NbbNnXc78wbUX4Wvc5bNoy46TbNcQ0pBbxqTmypMComMFJujgXhYmoFthjkHEAK49a7agsoDy8HZGKCOd7wbSrz8iT4G0sjoae1JTJMOihnVPfXdkDUO1naTnuVkQu1iiX7-2BUKJrQadXl-2FSumnQ-2FcHK0-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ST9LHNQ2kYRKURQJ7G-2FmGCudH8brFLVBGfh-2Becw1t9iLjsmdSlMEaHNMm02-2FieZxzWH-2BpUYDWtLX5-2FCHTtraP4rsMaBFcmuADGipWRYpiPITGcee4yHc-2FbF8cA3MHX7rmRbfSk89Yv3NisuLqH5fs6n7xqv0yHwLQN3iuN-2FoiEyWu2l0vq0PVdslpKeJfPZ14bm4SFUwT1sOd-2FbFmSII3M3sXFukYQu8aipWsNxep2o-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></body></html>