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

Antoon Pardon antoon.pardon at vub.be
Wed Sep 27 03:35:29 EDT 2017


Op 27-09-17 om 04:58 schreef Steve D'Aprano:
> A pedantic difference that makes no difference to my argument.
>
> I see that you ignored the later assignment:
>
> b = 2;
>
> which also assigned to a. *That** is the fundamental point: b is certainly an
> alias for a, and assigning to b assigns to a.
>
> That's how aliases work in C++. That's how var parameters in Pascal work, and
> out parameters in Ada. That is what it means to say that "b is an alias to a".

The main problem is that you keep using assignment as if an assignment in
languages like Pascal and C++ has an similar effect like as assignment in
Python and thus that if an assignment has an effect in one language it should
have that effect in other languages.

In C++ and Pascal talking about an assignment means, that we have a name that
refers to an object whose value was overwritten.

In Python an assignment means that we have name that will now refer to an other
object.

If two names are aliases they refer to the same object and when the value of that
object is modified through one name, it is visible through the other name. How
one modified that object is immaterial. It doesn't matter whether the 
modification/mutation was done through an asignment or an other kind of mutation.

It also doesn't matter what the label is, we use for the operation. The label
"assignment" is not magic. If in one context an assignment mutates and in an
other context it doesn't you can't interfere conclusions about the assignment
in the second context based on the effects an assignment has in the first context
because we are talking about two differnt operations that just use the same lable.

-- 
Antoon Pardon.





More information about the Python-list mailing list