<html><head></head><body>-1e200.<br>
<br>
I have to deal with implicit 'this' enough in C++ at the risk of writing "bad style" or something like that. It has bitten before. Until I started following C++ style guides, I always put 'this->' in front of every variable but still had to deal with the accidental member reference when you meant something else.<br>
<br>
I also like the fact that Python lets you name constructor arguments the same way as members, e.g.:<br>
<br>
class X:<br>
 def __init__(self, x, y):<br>
  self.x = x<br>
  self.y = y<br>
<br>
You can do the same in C++, but compilers with -Wall will complain unless you do this:<br>
<br>
class X {<br>
public:<br>
 X(int x_, int y_): x{x_}, y{y_} {}<br>
 ...<br>
}<br>
<br>
which is just ugly.<br>
<br><br><div class="gmail_quote">On July 10, 2015 5:31:28 PM CDT, Michael Hewitt <michael@hewitts.us> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr"><div>Last night I made a post to the neopythonic blog proposing a Python 3.x feature that Guido asked me to forward to this alias.  For the full background, see the link to my post below.  For brevity, I will simply submit the proposal here.  The specific problem I am addressing is the pollution of Python methods by 'self.' to reference fields.  Here is the proposal:</div><div><br /></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">The name of the first parameter to a method can be used to scope subsequent variable references similar to the behavior of 'global'.</span><br /></div></blockquote><div><br /></div><div>Here are some examples:</div><div><br /></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span
style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">class Foo:</span><br style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px" /></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">def method_a(self)</span></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">self x # subsequent 'x' references are scoped to
'self'</span></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">x = 5 # same as self.x = 5</span></div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">def </span><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">method_b</span><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">(this)</span></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px
40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">this x, y # subsequent 'x' & 'y' refs are scoped to 'this'</span></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">x = y # same as this.x = this.y</span></div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span
style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">def </span><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">method_c</span><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">(its)</span></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(51,51,51);font-family:Verdana,Arial,sans-serif;font-size:11px;line-height:17.68000030517578px">its.x = 5 # still works just like it used to</span></div></blockquote></blockquote></blockquote><div><br /></div><div>This suggestion is fully backward compatible with existing Python code, but would eliminate the need to pollute future Python methods
with copious 'self.' prefixes, thereby improving both readability and maintainabilty.</div><div><br /></div><div>Thank you for your consideration.</div><div><br /></div><div>Michael Hewitt</div><div><br /></div><div>Original Post:</div><a href="http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html">http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html</a><br /></div>
<p style="margin-top: 2.5em; margin-bottom: 1em; border-bottom: 1px solid #000"></p><pre class="k9mail"><hr /><br />Python-ideas mailing list<br />Python-ideas@python.org<br /><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br />Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></pre></blockquote></div><br>
-- <br>
Sent from my Android device with K-9 Mail. Please excuse my brevity.</body></html>