On 11/23/19 4:18 PM, Peter J. Holzer wrote: > On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: >> Instead, at a simple level (a common description invokes "Post-It" >> notes) >> >> x = y >> >> means /find/ the object (somewhere in memory) that has a note "y" stuck to >> it. Without moving the "y" note, attach an "x" note to that same object. >> The object now has two names bound to it. If the "x" note used to be >> attached to an object, the old object no longer has that name -- and if the >> object has NO names attached, it is garbage collected. > Frankly, I find that model very unsatisfying. > > It's not just that it doesn't describe any existing or even plausibly > possible implementation or that it implies a complexity that isn't there > (search for an object with a note attached to it?). It starts to break > down even for simple cases: There may be several variables called "x" in > a program. How does the system distinguish between multiple objects with > an "x" note? What about objects which have no name, like members of a > tuple or the return value of a function? Sure, you can come up with > arcane rules to on how to label a post-it to reference an object > referenced by the x parameter of the lamba on line 7 of the third > recursive invocation of function foo within the method bar of the Gazonk > class in the fred packagerbut called from Bobble ... (ok, I'll stop > now). But why would you? > > It's much simpler to talk about references or pointers or whatever you > want to call them. You can nicely visualize them with arrows (or pieces > of string, if you want, but arrows have the advantage of having a > direction) and it describes directly and without any mental gymnastics > what is going on (on a conceptual level - actual implementations might > be somewhat different, as long as they behave the same). > > hp
A post-it note analogy is a very good description to allow a non-technical person to understand how it works. Yes, as presented, it doesn't handle the concept of scope of variables, but that starts to get into more complexity than you might want for a simple model, and it is simple to extend to handle it, either every scope gets a different color post-it note, or when you write the name of the variable, you include the scope. To a non-techie, a 'Pointer' is either a breed of dog or an arrow pointing in a general direction. The key is that you are showing something fundamentally different than a box to hold a value. If you show names as boxes with arrows in them, someone is going to ask how to get one name point to another name (re the discussion about is it call by value or call by reference) -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list