Too Self Centered

Edward K. Ream edream at tds.net
Wed Jan 8 09:27:59 EST 2003


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

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------






More information about the Python-list mailing list