What other languages use the same data model as Python?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 4 06:51:33 EDT 2011


On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote:

> Python is pass-by-value in a
> meaningful sense, it's just that by saying that we say that the values
> being passed are references/pointers. This is maybe one level of
> abstraction below what's ideal,

"Maybe"?

Given the following statement of Python code:

>>> x = "spam"

what is the value of the variable x? Is it...?

(1) The string "spam".

(2) Some invisible, inaccessible, unknown data structure deep in the 
implementation of the Python virtual machine, which the coder cannot 
access in any way using pure Python code.

(Possibly a pointer, but since it's an implementation detail, other 
implementations may make different choices.)

(3) Something else.


I argue that any answer except for (1) is (almost always) counter-
productive: it adds more confusion than shedding light. It requires 
thinking at the wrong level, at the implementation level instead of the 
level of Python code. If we define "value" to mean the invisible, 
inaccessible reference, then that leaves no word to describe was the 
string "spam" is.

(I say "almost always" counter-productive because abstractions leak, and 
sometimes you do need to think about implementation.)


> but Scheme, Java, etc. share this
> terminology. (Ruby calls it pass-by-reference AFAIK.

The intellectual contortions that some people will go through to hammer 
the square peg of actual programming language behaviour into the two 
round holes of "pass by value" and "pass by reference" never cease to 
astonish me.


> Whatever, a rose by any other name...)

Do you really think that roses would be the symbol of romantic love if 
they were called "disgusting stink-weeds of perversion and death"?

"How was the date last night?"
"Oh, it was marvelous! He presented me with a single red stink-weed, and 
then we went to a disgusting little restaurant. I had the swill."

When people cannot agree on the definition of words, how can they 
communicate? Pass by reference Ruby is completely different from the 
older usage in Pascal, VB and other languages. Likewise, pass by value in 
Java is completely different from that in older languages. Pass by 
reference in Ruby, and pass by value in Java, describe the same thing. 
What were these people thinking?


-- 
Steven



More information about the Python-list mailing list