The meaning of a = b in object oriented languages
John W. Kennedy
jwkenne at attglobal.net
Thu Sep 20 20:47:57 EDT 2007
Russell Wallace wrote:
> Summercool wrote:
>> so most or all object oriented language do assignment by reference?
>> is there any object oriented language actually do assignment by
>> value? I kind of remember in C++, if you do
>>
>> Animal a, b;
>>
>> a = b will actually be assignment by value.
>> while in Java, Python, and Ruby, there are all assignment by
>> reference. ("set by reference")
>>
>> Is that the case: if a is an object, then b = a is only copying the
>> reference?
>
> Yes, your understanding is exactly correct; C++ will assign by value
> unless you explicitly use pointers, but the other languages will assign
> by reference (except for primitive types).
Ada also assigns by value absent explicit use of access variables
(similar to pointers or references).
The question, in fact, is meaningless. Java has a certain defined
behavior. C++ has a certain defined behavior. Smalltalk has a certain
defined behavior. LISP has a certain defined behavior. Ada has a certain
defined behavior. Object-oriented languages as a class do not.
--
John W. Kennedy
"The poor have sometimes objected to being governed badly; the rich have
always objected to being governed at all."
-- G. K. Chesterton. "The Man Who Was Thursday"
More information about the Python-list
mailing list