[Python-ideas] Mitigating 'self.' Method Pollution
David Mertz
mertz at gnosis.cx
Sun Jul 12 21:10:09 CEST 2015
>
> With the proposal, the above would actually read
>
> def abs(self):
> self x, y, z
> return sqrt(x**2 + y**2 + z**2)
>
> so it is obvious that z is not a global but an attribute of self.
>
Sure, and this exists right now as an option:
def abs(self):
x, y, z = self.x, self.y, self.z
return sqrt(x**2 + y**2 + z**2)
The small number of characters saved on one first line isn't worth the
extra conceptual complexity of learning and reading the next construct.
> > No one stops you now from giving local names to values stored in the
> > instance within a method body. But when you do so, you KNOW 30 lines
> later
> > that they are local names, even after the "local-looking name is actually
> > an attribute" declaration has scrolled away.
>
> As Steven has so nicely written in the mail that I responded to:
> | If you are writing "enterprisey" heavily object oriented code, chances
> | are you are dealing with lots of state, lots of methods, lots of
> | classes,
I don't buy it. I don't want a language construct that is meant to
self-destruct as soon as people's methods grow past 30 lines (yes, I know
it wouldn't literally do so, but there is a pretty small threshold beyond
which it turns from making "code golf" easier to actively harming
readability).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150712/5f365dcd/attachment-0001.html>
More information about the Python-ideas
mailing list