[Python-ideas] Mitigating 'self.' Method Pollution

David Mertz mertz at gnosis.cx
Sat Jul 11 03:34:24 CEST 2015


-1000

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

On Fri, Jul 10, 2015 at 3:31 PM, Michael Hewitt <michael at hewitts.us> wrote:

> 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:
>
> The name of the first parameter to a method can be used to scope
> subsequent variable references similar to the behavior of 'global'.
>
>
> Here are some examples:
>
> class Foo:
>
> def method_a(self)
>
> self x # subsequent 'x' references are scoped to 'self'
>
> x = 5 # same as self.x = 5
>
> def method_b(this)
>
> this x, y # subsequent 'x' & 'y' refs are scoped to 'this'
>
> x = y # same as this.x = this.y
>
> def method_c(its)
>
> its.x = 5 # still works just like it used to
>
>
> 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.
>
> Thank you for your consideration.
>
> Michael Hewitt
>
> Original Post:
> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150710/f64fbf7a/attachment.html>


More information about the Python-ideas mailing list