Origin of 'self'

  • Thread starter Westley Martínez
  • Start date
W

Westley Martínez

I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless.

Sincerely,
Westley Martínez
 
D

Dave Angel

Westley Martínez said:
I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless.

I couldn't tell you the history, but I can say it makes sense to
me. In c++, this is a pointer, and the name this seems
reasonable. But in python it's a reference, a reference to
myself.
 
S

Steven D'Aprano

I understand that in an object method the first argument in the object
itself, called self. However, it doesn't have to be called self, and
can be called anything. So my question is why is it called self and not
this like from C++ and Java. It's kind of a silly question, but one
that I'm curious about nevertheless.

A better question is why C++ and Java used "this" instead of "self" like
Smalltalk. It's fairly clear that Java copied C++, but why did C++ use
"this"?


http://en.wikipedia.org/wiki/Compar...bject-oriented_programming)#Special_variables


As far as I can tell, Simula 67 (the first OOP programming language)
doesn't seem to use a standard name for the current instance, it appears
to be unneeded. But Simula 67 was the inspiration for Smalltalk, invented
by Alan Kay at Xerox PARC in the 1970s, and Smalltalk used "self".
Virtually everything in OOP that followed was influenced by or derived
from Smalltalk.
 
I

Ian Kelly

I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this likefrom C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless.

The idea of requiring references to attributes and methods of self to
be explicit comes from Modula-3; likely the naming convention follows
the same lineage.
 
T

Terry Reedy

I understand that in an object method the first argument in the
object itself, called self. However, it doesn't have to be called
self, and can be called anything. So my question is why is it called
self and not this like from C++ and Java. It's kind of a silly
question, but one that I'm curious about nevertheless.

Three responses and I learned or had something pointed out in each. That
is a better track record than most threads.
 
D

Dennis Lee Bieber

I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless.

It didn't want to be egotistical (as I recall, M$ VB uses "me")
 
C

Chris Angelico

It didn't want to be egotistical (as I recall, M$ VB uses "me")

ALL language designers are egotistical. Goes with the territory.

(Larry Wall said that, I believe, regarding Perl.)

ChrisA
 
M

MRAB

It didn't want to be egotistical (as I recall, M$ VB uses "me")
So does AppleScript.

<OT>
In AppleScript a script can refer to the title of a window as "title of
window" or "window's title", and it can refer to the title of its own
window as "title of window of me" or "me's window's title". Consistent,
yes, but bad English.

That's why I prefer a programming language not to be too much like a
natural language. :)

</OT>
 
S

Steven D'Aprano

In AppleScript a script can refer to the title of a window as "title of
window" or "window's title", and it can refer to the title of its own
window as "title of window of me" or "me's window's title". Consistent,
yes, but bad English.

That's why I prefer a programming language not to be too much like a
natural language. :)

But the problem with that is not that it is too much like a natural
language, but too little like a natural language.
 
M

MRAB

But the problem with that is not that it is too much like a natural
language, but too little like a natural language.
The more it's like a natural language, the more intelligent you expect
it to be, and the more you expect it to be able to work out ambiguities
for itself.
 
R

Rustom Mody

In AppleScript a script can refer to the title of a window as "title of
window" or "window's title", and it can refer to the title of its own
window as "title of window of me" or "me's window's title". Consistent,
yes, but bad English.
That's why I prefer a programming language not to be too much like a
natural language. :)

<Continue-OT>

There could be other conclusions. Such as that English could learn
from AppleScript to not make bogus distinctions between me and my. Or
latin in which case is sufficiently explicit that word-order does not matter

<Even-more-OT>
Reminds me of
"How do we know whether smoking causes cancer or cancer causes smoking?"
</Even-more-OT>

</Continue-OT>
 
M

MRAB

<Continue-OT>

There could be other conclusions. Such as that English could learn
from AppleScript to not make bogus distinctions between me and my. Or
latin in which case is sufficiently explicit that word-order does not matter
Latin's not that explicit: the endings aren't unique within a
declension.
 
W

Westley Martínez

Why did C++ use this? I don't really like this. It doesn't sound right. I think it's because I have trouble saying the th sound without getting my mouth full of spit.

Thankfully you don't often need to use this in C++ like you do with self in Python.
 
M

Mark Lawrence

Why did C++ use this? I don't really like this. It doesn't sound right. I think it's because I have trouble saying the th sound without getting my mouth full of spit.

Thankfully you don't often need to use this in C++ like you do with self in Python.

You don't need to use self, you can call it anything you like, but
you'll not be particularly popular if you do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top