History of 'self' and why not at least 'my'?

Wolfgang Strobl ws at mystrobl.de
Fri Jan 11 18:34:01 EST 2002


On Fri, 11 Jan 2002 11:32:03 -0800, James_Althoff at i2.com wrote :

>Paul Rubin wrote:
>>Oleg Broytmann <phd at phd.pp.ru> writes:
>>>    "Self" was borrowed from Object Pascal family (Modula-3, I think).
>>
>>And also Smalltalk and maybe even Simula.
>
>Smalltalk was the first to use "self".  Simula used/uses "this".

Well, this is technically correct, but somewhat misleading. Using the
reserved word "this" was rarely necessary in Simula67, because a
methods body was implicitely qualified with the instance it was called
with. There was no visible first parameter "self" for methods.

See below for an example of a Simula program defining a trivial class,
followed by the roughly equivalent Python program.

----------------------

begin
   class pair(x,y);
   integer x;
   integer y;
   begin
      integer procedure sum;
      begin
         sum := x+y;
       end;
   end;
   
   ref(pair) a;
   ref(pair) b;
   
   a :- new pair(5,7);
   b :- new pair(10,20);
   
   outtext("a:"); outint(a.sum,10); outimage;
   outtext("b:"); outint(b.sum,10); outimage;
end;

----------------------

F:\simula>cim test.sim
Compiling test.sim:
gcc -g -O2  -c test.c
gcc -g -O2  -o test test.o -Lf:\simula\lib -lcim

F:\simula>test
a:        12
b:        30

----------------------

class pair:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def sum(self):
        return self.x+self.y

a=pair(5,7)
b=pair(10,20)
print "a:",a.sum()
print "b:",b.sum()

----------------------

a: 12
b: 30

-- 
Thank you for observing all safety precautions



More information about the Python-list mailing list