<div dir="ltr">-1000<div><br></div><div>This looks like an absolutely terrible anti-feature.  It makes all code less readable, and violates the principle of locality (albeit, `global` and `nonlocal` can also be declared relatively far away from the use of those scoped variables too).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 10, 2015 at 3:31 PM, Michael Hewitt <span dir="ltr"><<a href="mailto:michael@hewitts.us" target="_blank">michael@hewitts.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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" target="_blank">http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html</a><br></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><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div>