What other languages use the same data model as Python?

Devin Jeanpierre jeanpierreda at gmail.com
Wed May 4 09:12:14 EDT 2011


On May 4, 6:51 am, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> 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, unknowndatastructure 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.

As I said, a pointer or reference.

> 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.)

I don't know why you want to argue that it's counter-productive when
all I said was that it was meaningful / worked.

I don't think of "pass-by-value" involving references as being an
implementation-level thing. It's a way of thinking about Python's
behavior: a model. There don't even need to be actual references or
anything resembling them inside the implementation in order to apply
the model (for example, we probably all accept that Python could be
implemented using a turing machine, which lacks references/pointers).

Also, the word you suspected did not exist is "object". So if we have
var = "spam", var is a variable containing a reference to the object
"spam". Alternatively, it's a handle for the object "spam". I think
that's the call-by-sharing terminology, anyway.

> > 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.

It isn't particularly contorted. I learned Python this way and it
makes perfect sense. It's just perhaps one level of abstraction away
from the ideal of what some programmers would think in. Python's "pass-
by-value" conforms exactly to the "pass-by-value" of other languages
such as C. The only twist is that you never get to dereference
pointers in Python, but you can in C. Not much of a twist if you ask
me, but then again, I've been thinking in this model for years. Maybe
I'm brainwashed. :)

> > 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."

Please don't argue with me in this manner. The point is that words
don't matter, the meaning behind them does. As long as it's clear
what's meant, and what's meant is internally-consistent, I don't have
much problem with it. Of course, this is a rule of thumb and you could
draw extreme scenarios where it just becomes a bother.

Devin Jeanpierre




More information about the Python-list mailing list