Too Self Centered

beno zope at thewebsons.com
Wed Jan 8 17:50:03 EST 2003


At 02:27 PM 1/8/2003 +0000, you wrote:
> > I'm writing my first real script and running into what appears to be a
> > problem. Although this code works perfectly well, it seems to have way too
> > many uses of *self.* in it.
>
>I often use the following idiom for methods in Leo:
>
>def spam(self,...):
>
>     v = self
>     # Now use v instead of self
>
>The idea is to use one-letter codes for common classes. Leo uses c for
>"commanders", f for frames, t for Tk.Text widgets or "tnodes", v for
>"vnodes", u for "undoer" objects, etc.  With this idiom, objects of the
>class in which the method exists are handled just like all other objects.
>It saves typing and makes the type of all objects clear.
>
>One could use:
>
>def spam,(v,...):
>     # etc.
>
>instead, but that would violate the coding guidelines (and pychecker would
>complain by default).
>
>This scheme is simple, clear, concise, effective.  It has no drawbacks that
>I know of.

Thanks,
beno







More information about the Python-list mailing list