OT: C vs Python terminology

Dave Angel davea at davea.name
Sun Jun 16 08:55:18 EDT 2013


On 06/16/2013 07:22 AM, Andreas Perstinger wrote:
> On 16.06.2013 08:32, Denis McMahon wrote:
>> C:
>>
>> int a, b;
>> b = 6;
>> a = b;
>>
>> In C, this places the numeric value 6 into the memory location identified
>> by the variable "b",
>
> so far so good.
>
>> then copies the value from the location pointed to by "b" into the
>> location pointed to by "a".
>
> Wrong. Neither "a" nor "b" are pointers, thus they don't point to a
> memory location.
> This part should be written as
> "then copies the value at the location identified by "b" to the location
> identified by "a".

But it doesn't.  It binds b to the same object to which a is currently 
bound.
>
>> b is a pointer to a memory location containing the value 6
>  > a is a pointer to another memory location also containing the value 6
>
> Again, neither "a" nor "b" are pointers.
> "b" is the name of a memory location containing the integer value 6.
> "a" is the name of another memory location containing the integer value 6.
>

Not even close.  If you don't like the terms "bound" or "points", the 
perhaps you'd be happy with "b" is the name that currently knows how to 
find an int object containing 6.  That object has no name, and never 
will.  And it can exist for a long time with no names directly bound to it.

>> Python:
>>
>> b = 6
>> a = b
>>
>> In Python, this first puts the value 6 in in a memory location and points
>> "b" at that memory location, then makes "a" point to the same memory
>> location as "b" points to.
>>
>> b is a pointer to a memory location containing the value 6
>> a is a pointer to the same memory location
>
> I wouldn't use the term "pointer" in context with Python. Using the
> terms from the language reference I would write that as
> "In Python, this first creates an integer object with value 6 and then
> binds the name "b" to it. Then it binds the name "a" to the same object.
> Thus both "a" and "b" reference the same object, i.e. they are different
> names for the same object."
>
> Bye, Andreas

Doing all of this discussion with immutable objects masks the real 
behavior, as someone can use a false model and seem to justify that 
model.  I don't think you're doing that, but others in the thread are.

-- 
DaveA



More information about the Python-list mailing list