The meaning of a = b in object oriented languages

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Sep 18 09:34:24 CEST 2007


En Tue, 18 Sep 2007 03:57:36 -0300, Summercool <Summercoolness at gmail.com>  
escribi�:

> i think the line
>
> a = "different"
>
> means a is now set to a pointer to the String object with content
> "different".
> or that "a is now a reference to the String object."
>
> and b is still a reference to the Array object.  so that's why a and b
> print out different things.  they point to different objects.
>
> i think:
>
> whenever in Ruby, Python, and Java,
>
> a is never an object.  a is always a "reference to an object"...  this
> will solve a lot of puzzles when we don't understand some code
> behaviors.

Yes, but extrapolating that to "In OOPL, a=b just copies a reference" is  
wrong.
"Old" languages like Fortran use the "boxed" model, and "modern" languages  
tend to use the "reference" model, and since OO languages are younger...
But this rather old post by Alex Martelli explains it better  
<http://mail.python.org/pipermail/python-list/2001-April/077544.html>

-- 
Gabriel Genellina




More information about the Python-list mailing list