Direct vs indirect [was Re: why () is () and [] is [] work in other way?]
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Apr 27 13:06:51 EDT 2012
On Thu, 26 Apr 2012 04:42:36 -0700, Adam Skutt wrote:
> On Apr 26, 5:10 am, Steven D'Aprano <steve
> +comp.lang.pyt... at pearwood.info> wrote:
>> But I was actually referring to something more fundamental than that.
>> The statement "a is b" is a *direct* statement of identity. "John is my
>> father." "id(a) == id(b)" is *indirect*: "The only child of John's
>> grandfather is the parent of the mother-in-law of my sister-in-law"
>> sort of thing. (Excuse me if I got the relationships mixed up.)
>
> Again, the fact that you somehow think this absurd family tree is
> relevant only shows you're fundamentally confused about what object
> oriented identity means. That's rather depressing, seeing as I've given
> you a link to the definition.
Perhaps you failed to notice that this "absurd" family tree, as you put
it, consists of grandparent+parent+sibling+in-law. What sort of families
are you familiar with that this seems absurd to you?
I think you have inadvertently demonstrated the point I am clumsily
trying to make. Even when two expressions are logically equivalent, the
form of the expressions make a big difference to the comprehensibility of
the text. Which would you rather read?
for item in sequence[1:]: ...
for item in sequence[sum(ord(c) for c in 'avocado') % 183:]: ...
The two are logically equivalent, so logically you should have no
preference between the two, yes?
> In a mathematical sense, you're saying that given f(x) = x+2, using f(x)
> is somehow more "direct" (whatever the hell that even means)
I thought that the concept of direct and indirect statements would be
self-evident. Let me try again.
A statement is "direct" in the sense I mean if it explicitly states the
thing you intend it to state. A statement is "indirect" if it requires
one or more logical steps to go from the statement, as given, to the
conclusion intended.
"Queen Elizabeth II is the ruling monarch of the United Kingdom" is a
direct statement of the fact that Queen Elizabeth II is the ruling
monarch of the UK. (Do I really need to explain this?)
"Queen Elizabeth II is the Commander-in-chief of the Canadian Armed
Forces" is an *indirect* statement of the fact that Elizabeth is the
ruling monarch of the UK. It is indirect because it doesn't explicitly
say that she is monarch, but the Commander-in-Chief of the Canadian Armed
Forces is always the ruling monarch of Canada, and the ruling monarch of
Canada is always the ruling monarch of the UK. Hence, Elizabeth being
Commander-in-Chief necessarily implies that she is ruling monarch of the
United Kingdom (at least until there is change to Canadian law).
"a is b" is a direct test of whether a is b. (Duh.)
"id(a) == id(b)" is an indirect test of whether a is b, since it requires
at least three indirect steps: the knowledge of what the id() function
does, the knowledge of what the == operator does, and the knowledge that
equal IDs imply identity.
--
Steven
More information about the Python-list
mailing list