<div dir="ltr"><div>Hi.</div><div><br></div><div><span class="im" style="font-size:12.8000001907349px">Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> writes:<br><br>> Personally, I don't think of "self" as pollution at all. It's nice and<br>> explicit and helps readability.<br><br></span><span style="font-size:12.8000001907349px">+ 1 as well</span><br></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">I am definitely in the conservative camp (I don't know who else but I am). </span>Let's stick to Zen of Python.</div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">* I see no real use case why I would write self x,y instead of self.x = 1, self.y = 2. This reminds me of Javascript var x,y.</span></div><div><span style="font-size:12.8000001907349px">* While this is not exactly like Javascript's "this", I can see the resemblance, and no thanks.</span></div><div><span style="font-size:12.8000001907349px">* This change will be confusing to everyone reading Python code. We have to stick to real readability, not some rare . We should not introduce this kind of change to say "we can do X in two ways, and most people will write in the old convention ANYWAY but be hold there is a second geeky way to do the same thing."</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div>Let's reserve the idea that</div><div>self x where now x is scoped to self .... reserve this idea to just nonlocal and global - I personally haven't found a use case for nonlocal and global in my own work but that's just my opinion.</div><div><br></div><div>Thanks.</div><div>John</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 10, 2015 at 10:42 PM, Ryan Gonzalez <span dir="ltr"><<a href="mailto:rymg19@gmail.com" target="_blank">rymg19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>-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"><div><div class="h5">On July 10, 2015 5:31:28 PM CDT, Michael Hewitt <<a href="mailto:michael@hewitts.us" target="_blank">michael@hewitts.us</a>> wrote:</div></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
<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" target="_blank">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></div></div><pre><hr><span class=""><br>Python-ideas mailing list<br><a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a></span></pre></blockquote></div><span class="HOEnZb"><font color="#888888"><br>
-- <br>
Sent from my Android device with K-9 Mail. Please excuse my brevity.</font></span></div><br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br></div>