[Python-ideas] "value" ~ "data" ~ "object"

Guido van Rossum guido at python.org
Thu Apr 15 20:36:28 CEST 2010


2010/4/15 spir ☣ <denis.spir at gmail.com>:
> On Thu, 15 Apr 2010 14:31:49 +0100
> Conrad Irwin <conrad.irwin at googlemail.com> wrote:
>
>>
>> On 04/15/2010 12:37 PM, spir ☣ wrote:
>> > Hello,
>> >
>> > I have been recently thinking at lexical distinctions around the notion of data. (--> eg for a starting point http://c2.com/cgi/wiki?WhatIsData) Not only but especially in Python. I ended up with the following questions:
>> > Can one state "in Python value=data=object"?
>> > Can one state "in Python speak value=data=object"?
>> >
>> > What useful distinctions are or may be done, for instance in documentation?
>> > What kind of difference in actual language semantics may such distinctions mirror?
>>
>> Uh.. you are trying to have a discussion about detailed semantics
>> without defining what you mean by any of your terminology.
>
> This is precisely the point: how to properly use given terms -- giving them semantic distinctions or not.

Data is a buzzword.

Object is, well, an object. It has a distinct
id/address/location/whatever. (Though these may be reused after an
object is destroyed.)

Value is semantically defined by the type/class -- e.g. for numbers,
two objects with the value 1 have the same value (even if the type is
different, e.g. 1 and 1.0); and similar for strings. But for other
object types the value is just the object identity. And for tuples it
actually depends on the items. IOW values are defined by __eq__.

>> [...]
>
>> (and for the most part, objects with the same values have different data too).
>
> Right, this makes sense for me. And do you mean data are different as soon as located at different places in memory even if bit-per-bit equal? Or only that value holds a notion of interpretation (due to the type)?

There is no notion of bit-per-bit equal. Only object identity (same
address) and value equality defined by __eq__.

>> [...]
>
>> It shouldn't
>> be necessary to make the distinction between an object and its value in
>> documentation (though it is (I presume) occasionally useful in actual
>> code to distinguish objects with the same datum, perhaps in cycle
>> detection).
>
> Thank you. Let us take the case of a simple assignment:
>   name = expression
> Once the expression is evaluated, what we get is commonly called a value, right?

No, an object. (Which has a value but the meaning of the value depends
on the type.)

> But in numerous places the result of data lookup is called object instead.

Please stop using 'data'. It has no meaning in this context.

> While conceptually, for me, it's exactly the same thing.
>   x.a = 1
> results in an attribute 'a' with "value" 1, in x.

No, attribute lookup returns an object, not a value.

>   b = x.a
> looks up for the "object" denoted to by the attr name 'a' in x.

All this is defined by object semantics. Value semantics apply at a later level.

> (I'm not trying to annoy people, just to clarify common notions.)

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list