<div dir="ltr">@Andrew: I agree that the discussion got a little sidetracked with people debating whether self should be required at all in closures. I personally think that your proposed solution may lead to needless ambiguity and confusion with regards to self-capture, and I would be careful with bringing it up as it could be a point of contention that may derail the discussion further. I personally don&#39;t agree with it but will reserve my judgment in the interest of staying on the topic of mandatory self.<div><br></div><div>Could anyone provide a reasonably unbiased round-up of the pros/cons so far presented regarding required self capture?</div><div><br></div><div>To start, on the pro side I have heard -- </div><div>- Differentiates locals and ivars, making code ostensibly more readable</div><div>- Makes code more refactorable (proposed by me, counterargument: it may not be good to be able to move code around willy-nilly to and from closures when considering capture semantics)</div><div><br></div><div>And on the con side, I have heard --</div><div>- Annoying to do</div><div>- Makes it harder to move from local to instance context</div><div>- Makes code ostensibly less readable through &quot;self&quot; proliferation</div><div><br></div><div>Unless I missed something (very possible seeing as I believe I&#39;ve entered this discussion somewhat late), the rest seems to be anecdotal data and there does seem to be a solid split between the two schools.</div><br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 13, 2015 at 5:14 PM Andrew Brown via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>I think the requirement to use self in closures complicates the discussion.  Perhaps if this could be modified first it would help.  Perhaps instead of self to indicate capture, we should use weak/strong/unowned etc as keywords to be explicit about the type of capture.</div><div><br></div><div>then the discussion on self wouldn&#39;t be side tracked with this?</div><div><br></div><div><ol style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none"><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">class</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">HTMLElement</span> {</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><br></font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">    </font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">  let</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">name</span>: <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">String</span></font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">  let</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">text</span>: <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">String</span>?</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">    </font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline"><br></span></font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">  lazy</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">var</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">asHTML</span>: <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">Void</span> -&gt; <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">String</span> = {</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">    if</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">let</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">text</span> = unowned.<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">text</span> {</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">      return</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">&quot;&lt;</span>\(weak.<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">name</span>)<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">&gt;</span>\(<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">text</span>)<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">&lt;/</span>\(weak.<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">name</span>)<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">&gt;&quot;</span></font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">    } <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">else</span> {</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody"><span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">      return</span> <span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">&quot;&lt;</span>\(unowned.<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">name</span>)<span style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline"> /&gt;&quot;</span></font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">    }</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">  }</font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">    </font></code></li><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word;background-color:rgba(255,255,255,0)"><font face="UICTFontTextStyleTallBody">}</font></code></li></ol></div><div><br></div><div>ABR.</div><div><br>On 7 Dec 2015, at 01:10, David Hart via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>Hi Nick,<div><br></div><div>I understand the quote &quot;This makes the capturing semantics of self stand out more in closures”, but this is a very weak statement in Swift for me. Let me try to explain.</div><div><br></div><div>If we use the <font face="Menlo">try</font> keyword as an example:</div><div><br></div><div><font face="Menlo">try foobar()</font></div><div><font face="Menlo">barfoo()</font></div><div><br></div><div>If the previous lines of code compile without error, we know without a shadow of a doubt that <font face="Menlo">foobar</font> is a throwing function and that <font face="Menlo">barfoo</font> does not throw. The compiler will not compile the first line without the keyword and would not allow it in on the second line.</div><div><br></div><div>Now if we go back to the example of self in closures:</div><div><br></div><div><font face="Menlo">foobar({</font></div><div><font face="Menlo"><span style="white-space:pre-wrap">        </span>print(self.description)</font></div><div><font face="Menlo">})</font></div><div><br></div><div>The <font face="Menlo">self</font> keyword in the previous lines of code does not tell us anything at all:</div><div><br></div><div><ul><li><font face="Menlo">self</font> might have been forced by the compiler to warn us.</li><li><font face="Menlo">self</font> might have been a programmer choice if the closure was non-escaping.</li></ul><div><br></div></div><div>And the reverse:</div><div><br></div><div><div><font face="Menlo">barfoo({</font></div><div><font face="Menlo"><span style="white-space:pre-wrap">        </span>print(description)</font></div><div><font face="Menlo">})</font></div></div><div><font face="Menlo"><br></font></div><div>This also does not tell us much:</div><div><br></div><div><ul><li>The closure might be non-escaping.</li><li><font face="Menlo">description</font> might be referring to a local variable (which we missed the declaration) shadowing the instance property in an escaping closure.</li></ul><div><br></div><div>In both of these last examples, we can’t tell by having a quick look at the code at the point of call if we should really be careful about memory or not.</div><div><br></div><div>With the proposition, <font face="Menlo">self</font> gets some meaning back: it indicates which are local and which are instance properties.</div><div><br></div><div>David.</div><div><br></div></div><div><br><div><blockquote type="cite"><div>On 06 Dec 2015, at 23:55, Nick Shelley via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr">I like that self is only required in closures because it serves as a good reminder that there are memory and safety implications with using self in a closure, such as creating retain cycles or having the closure run after self has been deallocated.<br><div><br></div><div>I can&#39;t seem to find an official Apple Swift style guide, but github&#39;s (<a href="https://github.com/github/swift-style-guide" target="_blank">https://github.com/github/swift-style-guide</a>) suggests only using self in closures with the rationale: &quot;This makes the capturing semantics of self stand out more in closures, and avoids verbosity elsewhere.&quot;</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 5, 2015 at 3:16 AM, Yichen Cao <span dir="ltr">&lt;<a href="mailto:ycao@me.com" target="_blank">ycao@me.com</a>&gt;</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">Teaching wise, its much less confusing for self to be required so students don&#39;t mix up instance properties and local vars. Especially when self is required in closures, it confuses students. If self is mandatory for all instance properties, it would be so much clearer and much easier to read.<br><div>
<br><span style="font-family:Helvetica;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">Yichen</span>

</div>
<br><div><blockquote type="cite"><div>On Dec 5, 2015, at 18:11, <a href="mailto:swift-evolution-request@swift.org" target="_blank">swift-evolution-request@swift.org</a> wrote:</div><br><div><span style="font-family:Helvetica;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">Re: Proposal: Re-instate mandatory self for</span><span style="font-family:Helvetica;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:pre-wrap;word-spacing:0px">        </span><span style="font-family:Helvetica;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">accessing</span><br style="font-family:Helvetica;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"><span style="font-family:Helvetica;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">     instance properties and functions (David Hart)</span></div></blockquote></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43hXwizS3O2z60WweqomIrdh885WGIgW1Y9cOEYBC1Bdi4-2FlEXwKeFNR3ZjPNv-2Fo5F3OuL0oC2ftKbmmTWUPpZLsAdq6UMl0r0L9zFFO81EA5WQ-2F3Xkq6HQTFaQHbi9LYhCS8cJgXeLZN8nJshdFpWLo0oUypEwbdCN58u7KsSJhjqRAJLcUgz8zCtGMBYNIONMi27hfFM88sKE7koZLG9Io-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; display: none !important;">
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">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>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=XyCJWhfMItFjSNmahITOc00ZqJFxZGBHoC7Pq7qmjKiNfULSjvHi-2FoLhrz6IdA4h8H1dkMPUxioDbZ7iotp6grXYkjoysx2UFF7KAqhwYzZM2st5EX2QH61RUc18Lm7KGcdttpZDGRn-2BxFdvzaSVJpzFfMd6TpxUz6fDcQjzqpQSw8lx1dy876mCTZrJxgiW-2Bd8-2BbhqaEMmdJ8dJ7SpFKw-3D-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; display: none !important;">

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">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>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPeKdeAA0dvQxzuMtByW-2FDwmIRAff-2FDQ5-2BB1vIMB7UO1xr62AvS5KuUZFgT2QBNZhwejKCXzuWPGbGr7B1ICEh-2B9BQR2RYeet5VKwULM8PTGZuMyVnVXFyoeXGqRTRHdc3sC-2FDg9t-2BNOfXnNdRGa5ekv2Q26D3JRBN2InhtzT3HMJ4MhFLwOe-2Bs3PczlUuzYKDk-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; display: none !important;">
</div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>