Aliasing [was Re: [Tutor] beginning to code]

ROGER GRAYDON CHRISTMAN dvl at psu.edu
Wed Sep 27 07:19:21 EDT 2017


On Tue, Sep 26, 2017 11:00 PM, Steve D'Aprano <steve+python at pearwood.info>
wrote:
>
The critical distinction here is whether the names refer to each other:
>
>a <---> b
>
>or whether they merely refer to the same value:
>
>a ---> [ value ] <--- b
>
>
>Python uses the second model. Var parameters in Pascal and references in C++
use
>the first. Since the term "aliasing" is well-established for the first, using
>it in Python *without making the difference clear* is wrong.
>
>
>

Aha!  There is the fundamental problem.
In your first diagram below, if a is a pointer to b, and b is a pointer to a,
then where is the value?    

If the value of 1 (or 2) is in a, then a cannot point at b;

Or are you saying now that all variables in Pascal and C
are _both_ values and pointers, simultaneously?

Does that mean then that the value 1 (or 2) is in _both_  a and b?
So that an assignment to either must change both copies of the value?

No, I think it is more likely to be that the second diagram applies
in all cases.   Simply declaring a variable like A would lead to

a --> [ uninitialized ]

int& b creates an alias to a leads to

a -> [ uninitialized ] <- b

and then any assignment to a or b in the non-Python languages
under consideration would fill in that box, allowing the change
to be visible to both.

But in Python, _all_ assignments are aliases.

And I'll leave off further discussion by referring back to my
previous note about what happens when we do "b = c"
in the non-Python languages and in Python.

>From the ordering of the notes in this forum, I will just assume
you did not get a chance to read it before this post I am responding to.

Roger Christman
Pennsylvania State University




More information about the Python-list mailing list