Proposal for removing self

Dave Benjamin ramen at
Fri Aug 27 18:22:51 CEST 2004

In article <1gj65zl.1cuz9ub5xyo3rN%aleaxit at>, Alex Martelli wrote:
> Delaney, Timothy C (Timothy) <tdelaney at> wrote:
>> Andrea Griffini wrote:
>> > I remember Alex Martelli advocating in our italian newsgroup on
>> > C++ that C++ programmers should use "this->..." everywhere :-)
>> I evangelise this here (mainly for Java code these days, but close
>> enough). Unfortunately, I don't seem to be able to convince anyone else
> While it's also a good idea in Java, it's not as compelling as in C++,
> because Java mostly lacks the complications due to C++'s templates and
> freestanding ("not inside a class") names (haven't looked at Java
> generics so I don't know if they got those complications back in;-).

Java's generics aren't nearly as liberal as C++ templates. They're basically
just syntax sugar for casting, so I doubt this would change much. I still
prefer the explicit "this." or "self.", mainly because it is a pattern that
I can use consistently across all of the languages I regularly program in
(JavaScript and ActionScript, like Python, make "this" mandatory as well).

I like it better, stylistically, because I feel like I can determine more
readily where things are coming from, but each language has its own scoping
rules (Java has no modules, for instance. I wonder how it works for inner
classes...) so I can't really make an argument across the board that
"this." / "self." is always better.

That said, if an existing C++ or Java code base uses prefixes for all
instance variables, it's a bit redundant to add "this.". I have this
situation at my work, where I reluctantly have to make an exception to avoid
pissing people off. ;)

 .:[ dave benjamin: ramen/[sp00] -:- -:- ]:.
        "talking about music is like dancing about architecture."

More information about the Python-list mailing list