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

Chris Angelico rosuav at gmail.com
Sat Jul 11 03:04:07 CEST 2015

On Sat, Jul 11, 2015 at 10:06 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 07/10/2015 05:01 PM, Paul Sokolovsky wrote:
>> If you have troubles explaining why "self" is needed to kids, I'd
>> suggest going along the lines of why there's capital letter at the
>> start of sentence, full stop at the end, and wh hmn lnggs hv vwls, vn
>> thgh ts pssbl t rd wtht thm.
> +1 QotW  :)

Hebrew and Arabic manage without vowels. English manages (almost)
without diacriticals. Hungarian (I think) manages without verb tenses.
Chinese and Japanese can manage without punctuation, although these
days they usually use it.

And Python manages without declared variables, which is why 'self.x =
self.y' is completely different from C++ and family. But that also
means that it's different from the JavaScript 'with' block, because
the "self x, y" declaration is explicit about exactly which names are
scoped that way. This wouldn't have that problem.

However, I'm not sure it would be all that useful. Also, the current
definition means that the first parameter magically becomes a keyword
during the parsing of that function, which is extremely odd. I'm not
seeing huge value in this, given that the declaration means yet
another place to repeat all your attribute names; the only way I could
imagine this being smoother is if you could make your declaration at
class scope, and then it applies to _all_ the functions defined in it
- but that wouldn't solve the problems either.


More information about the Python-ideas mailing list