<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>