What is the semantics meaning of 'object'?

S

Steven D'Aprano

On 06/23/2013 11:50 AM, Steven D'Aprano wrote:

Well, I would call it super(). Trouble is, that is not all that super()
does. Going back to Ian's example:


Notice how Base1 calls super(), but depending on circumstances, it could
by Base2 that super() calls. Surely you are not suggesting that Base2
is therefore an ancestor of Base1?

No. But "the current object" is not Base1, but an instance of Derived,
and Base2 *is* an ancestor of Derived. Perhaps if I had said "self"
instead of current object, you wouldn't have made this error. If so, I
apologise for confusing you.

When your inheritance chain begins from an instance of Base1, Base2
methods will never be called. It is only when the chain begins from
Derived that Base2 may be called, which is exactly as it should be.

It's too late to change the name now, but pretending there is no good
and valid reason for confusion doesn't help.

The confusion is not with the name, or what super does, but with
inheritance itself.
 
E

Ethan Furman

No. But "the current object" is not Base1, but an instance of Derived,
and Base2 *is* an ancestor of Derived. Perhaps if I had said "self"
instead of current object, you wouldn't have made this error. If so, I
apologise for confusing you.

No apology necessary. I understand both inheritance and super fairly well, and you did not confuse me.

When your inheritance chain begins from an instance of Base1, Base2
methods will never be called. It is only when the chain begins from
Derived that Base2 may be called, which is exactly as it should be.

Absolutely. That doesn't change the fact that when writing Base1 you are still using the word 'super', and hopefully
remembering that even though it's named 'super' it may in fact call an object that is sideways from where you're at now
and have absolutely no relation to Base1's ancestors.

The confusion is not with the name, or what super does, but with
inheritance itself.

Good names are important because a good name can help alleviate confusion. A bad name can exacerbate it. Given the
terminology of superclasses and subclasses, naming a function 'super' that can in fact call another class that is in no
way the superclass of the class in which it is written, can easily cause confusion.
 
I

Ian Kelly

No. But "the current object" is not Base1, but an instance of Derived,
and Base2 *is* an ancestor of Derived. Perhaps if I had said "self"
instead of current object, you wouldn't have made this error. If so, I
apologise for confusing you.

If I am reading a class definition and see the code
super().__init__(), and I am not familiar with super() and do not
bother to go look it up in the docs because it looks "obvious" (or
perhaps I have read a tutorial that simply mentions that super() is
used to call methods from a superclass and elides over the details) --
my assumption is not going to be that super() is looking into
superclasses relative to the class of self, but more simply that
super() is looking into superclasses relative to the class that I'm
currently reading.

Why? Because that's the way that "super" works in every other
language I know of that has it.

Java: super looks depth-first from the contextual class (no multiple
inheritance allowed)
Ruby: super looks depth-first from the contextual class (no multiple
inheritance allowed)
Objective-C: super looks depth-first from the contextual class (no
multiple inheritance allowed)
Perl 5: by default, super looks depth-first from the contextual class
(multiple inheritance IS allowed; the C3 linearization (MRO) CAN be
used, but it must first be explicitly enabled with a pragma directive)

Now if you're coming from Java, Ruby, or Objective-C and reading a
Python super() statement, then hopefully you will stop and think,
"Hey, wait a minute. [Other language] doesn't have multiple
inheritance and Python does, so how does super() work here?" More
likely though you're not even thinking about multiple inheritance when
you read that statement, and you just assume that it works exactly
like the super keyword that you're used to, and you move on.
 
A

alex23

Did you ever hear of the Glass Bead Game?

Which was Hesse's condemnation of the
pure-academic-understanding-unbound-by-pragmatic-use approach as mental
masturbation, _not_ a recommendation for how human knowledge should
work. If you think otherwise, you might want to read the last few
chapters again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top