shortcut for 'self' wish

Will Ware wware at world.std.com
Fri Mar 2 21:43:56 EST 2001


Costas Menico (costas at meezon.com) wrote:
> Since Python lets you declare your own self it maybe better to change
> the 'self' to a single letter standard.  Maybe m.property or m.method...
> def myMethod(self, arg1, arg2): ..... def myMethod(m, arg1, arg2):
> This would save a lot of typing and encourage using OOP more,

Nobody will have any complaints about you using this in your own code
but it may be an uphill battle to get it accepted as a general social
convention. The "self." convention has a lot of history behind it and
is self-explanatory (much more so than "m." is m-explanatory).

Another possibility might be to check whether your editor supports some
kind of keyboard macro, so that you can type one key and the editor
fills in "self." for you. I think you could pretty easily to this in
either Emacs or vi. Then you get to save typing without violating the
prevailing convention.

Another thought: write code with just the leading period, and write a
program to perform the translation for you, from '\.[a-zA-Z]' to 'self.x'.
That's a maintainability problem waiting to happen though; you're really
better off with the keyboard macro.

As far as encouraging the use of OOP, its efficacy as a means to manage
some kinds of complexity will be a much bigger decision factor than
saving a few keystrokes here and there.
-- 
-----------------------------------+---------------------
 22nd century: Esperanto, geodesic | Will Ware
 domes, hovercrafts, metric system | wware at world.std.com



More information about the Python-list mailing list