Terminology: "reference" versus "pointer"
harvesting at makes.email.invalid
Sat Sep 12 22:02:51 CEST 2015
Rustom Mody writes:
> And yet doing
>>>> a = "Oops!"
> gives a data structure one "Oops!"
> whereas doing it to b mysteriously gives 2
> Best I can see you can only explain this
> with box-n-arrow diagrams.
> Or some moral equivalent.
I think the best way is to say that a and a are the same object,
while b and b are different objects. Possibly b is also the
same object as a and a. Then b = "Oops!" was redundant.
And the way to work out whether two objects are the same is to trace
where they come from. Certain pieces of code result in new objects.
Other pieces of code pass old objects around. Possibly store them in
places, or change them in some way. Never make copies.
Works for me.
Some sort of pointer-talk is useful to discuss the implementation of all
this (how can an object be in different places? how does an arbitrary
object fit in a 64-bit register?) but for ordinary reasoning about a
program, pointer-talk with those diagrams mostly gets in the way.
More information about the Python-list