What was the rationale for choosing the name self instead of this when defining class methods in Python?

Yes, of course, you can name it whatever you want - but the widely agreed-upon name for the first parameter is very clearly self.

I ask because there was an article about Robert Dewar explaining why : was added to the end of block statement lines (e.g. if foo:, def foo():), where his wife, Karin, looked at it passively and mentioned it wasn't as readable without it. So I wondered if there would be a similar explanation for Guido or the Python community to choose self over this.

  • 2
    I think the article you refer to is python-history.blogspot.com/2011/07/…; it was Karin Dewar, and for ABC. – jonrsharpe Nov 10 '19 at 13:01
  • 8
    Why the downvotes? Stupid question or not, it's still a valid one about software design. Man, SO is not the place it used to be... – Qix - MONICA WAS MISTREATED Nov 10 '19 at 17:37
  • 5
    Whoever voted to close as Primarily Opinion Based, this is a historical question able to be answered with a concrete, single, verifiable answer (as the accepted answer has done). I don't even know why I bother with this site anymore. – Qix - MONICA WAS MISTREATED Nov 11 '19 at 3:57
  • 2
    Qix, pretty everyone knows who would have incorrectly voted to close your question as he votes to close almost every question asked here. But the admins refuse to deal with him. So please just ignore it and him and don't let it put you off this site. – David Arno Nov 11 '19 at 8:36
  • 1
    @DanChase "But I think it's answerable if someone can find the people who were involved" Those people are the "God" that's being referred to in the phrase "word of God". – Flater May 6 '20 at 9:24

The use of self can be traced back to Smalltalk, which is one of the eldest OO languages (the oldest according to python wiki) and influenced the python language designers:

  • There is evidence of a direct influence of Guido Van Rossum, since he was inspired for the early Python bytecode by the Smalltalk bytecode (see footnote 9 on page 26 of this article):

  • There is also evidence of an indirect influence in the python documentation that refers to a Modula-3 origin of the explicit self, Modula-3 being influenced by Smalltalk for its object an inheritance model, not to speak about Niklaus Wirth, the spiritual father of Modula who spent 2 years at Xerox Parc where Smalltalk was invented.

Smalltalk used self instead of this. It also used super. In that language, Kay probably opted for self because of its message passing paradigm: it reflects better the semantic to send a message to self rather than sending a message to this.

The C++ tradition of this, that Java inherited, is to be traced back to the Simula language, which used a THIS reference (see the book "The design and evolution of C++" by Bjarne Stroustrup, page 36). Interestingly, Stroustrup explains that he had also to decide between this and self and he decided to opt for the Simula terminology rather Smalltalk's one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.