Why do pythonistas call the current reference “self” and not “this”?

后端 未结 8 1662
终归单人心
终归单人心 2020-12-13 12:13

Python is the language I know the most, and strangely I still don\'t know why I\'m typing \"self\" and not \"this\" like in Java or PHP.

I know that Python is older

相关标签:
8条回答
  • 2020-12-13 13:10

    Smalltalk-80, released by Xerox in 1980, used self. Objective-C (early 1980s) layers Smalltalk features over C, so it uses self too. Modula-3 (1988), Python (late 1980s), and Ruby (mid 1990s) also follow this tradition.

    C++, also dating from the early 1980s, chose this instead of self. Since Java was designed to be familiar to C/C++ developers, it uses this too.

    Smalltalk uses the metaphor of objects sending messages to each other, so "self" just indicates that the object is sending a message to itself.

    0 讨论(0)
  • 2020-12-13 13:12

    I think that since it's explicitly declared it makes more sense seeing an actual argument called "self" rather than "this". From the grammatical point of view at least, "self" is not as context dependent as "this".

    I don't know if I made myself clear enough, but anyway this is just a subjective appreciation.

    0 讨论(0)
提交回复
热议问题