the annoying, verbose self

Patrick Mullen saluk64007 at gmail.com
Fri Nov 23 20:16:25 EST 2007


Most of the time self doesn't bother me in the slightest.  The one
time it does bother me however, is when I am turning a function into a
method.  In this case, often I have many local variables which I
actually want to be instance variables, so I have to add self to all
of them.  Of course, this is going to cause me some grief no matter
which language I am using.  If it was enough trouble, it wouldn't be
hard to make a filter that converts my code automatically.

In other cases it's not a big deal.  When I program in java I write
"this." on everything anyway, as my Java teacher recommended.  So for
me it's not different than java, the way I write it.

I don't particularly like too much use of special characters, such as
the @ in ruby.  I actually don't like the @ in python for decorators
either.  So ugly :(  I would not like to see a special character or
leading dot used for attributes for this reason.  Human readable text
is nice, because even if you haven't programmed in the language for a
while, you don't have to remember as many special symbols.

I think using s. is your best bet, but for me, s is then just another
special character that needs to be memorized, whereas self. is self
descriptive.

One persons trash is another person's treasure.

On Nov 23, 2007 4:56 PM, hdante at gmail.com <hdante at gmail.com> wrote:
>
>  Hi,
>
>  Python uses "self" (and textual notation when possible) because its
> designers consider that symbols reduce readability. Self won't go
> away. :-P
>
>  The issue is related to the first and seventh lines in The Zen of
> Python,
>
>  1. "Beautiful is better than ugly"
>  7. "Readability counts."
>
>  My opinion is that "self" is a minor issue in python that we can all
> live with.
>
>
> On Nov 21, 9:51 pm, braver <delivera... at gmail.com> 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?
> >
> > Cheers,
> > Alexy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list