Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

python - Why do pythonistas call the current reference "self" and not "this"?

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 than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.

So where does this convention come from?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...