Is it advisable to replace 'self' with '_' or 'I' or something
Mel Wilson
mwilson at the-wire.com
Mon Jan 13 10:52:24 EST 2003
In article <3E210503.9A4F4AC8 at alcyone.com>,
Erik Max Francis <max at alcyone.com> wrote:
>"Jonathan P." wrote:
>
>> I agree with the fact that explicit use of self is good
>> for code readability, however it tends to make code lines
>> too long. Since 'self' is just a convention, I wonder if
>> people out there have tried replacing it with a one-character
>> equivalent without encountering any problems.
>>
>> I was thinking of using '_' ('I' is a distant second
>> choice) instead of self. Comments?
>
>I would consider any systematic use of a self parameter named something
>other than `self' a near perversity. You're just begging for confusion.
>
>If you want to rebind it in the method, fine.
As a tiny addition: I seem to find it more useful to
rebind entire variables, so that I write
t = self.tree
t.yadayada()
t.usw ()
rather than
s = self
s.tree.yadayada()
s.tree.usw ()
That's dummy code, of course .. real code would look like:
t = self.tree
i = t.AppendItem (parent, text)
t.SetPyData (i, data)
t.EnsureVisible (i)
A shortcut to an important local variable seems more
motivated, somehow.
Regards, Mel.
More information about the Python-list
mailing list