the annoying, verbose self

Farshid Lashkari no at
Thu Nov 22 01:06:12 CET 2007

braver wrote:
> Is there any trick to get rid of having to type the annoying,
> character-eating "self." prefix everywhere in a class?  Sometimes I
> avoid OO just not to deal with its verbosity.  In fact, I try to use
> Ruby anywhere speed is not crucial especially for @ prefix is better-
> looking than self.
> But things grow -- is there any metaprogramming tricks or whatnot we
> can throw on the self?

The most common answer you are going to get is that explicit is better 
than implicit, which I tend to agree with. Some people use 's' instead 
of 'self'. This shortens the number of characters you have to type, and 
is only one character more than the Ruby '@' prefix.

Here is a metaprogramming technique that removes self, but I don't 
recommend these sorts of things, especially if other people are going to 
be looking at your code in the future. So use it at your own risk!


More information about the Python-list mailing list