New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support isSubclassOf / isSuperclassOf / isAncestorClassOf / isDescendantClassOf #3416
Comments
In most cases, it is not a good style to write code based on inheritance, because it limits polymorphism (It's generally better to ask But in principle, this is a reasonable suggestion, as long as we don't encourage its use too much. |
Some semantics are slightly vague. By That aside, Checking for immediate sub/superclass is different then So while I can see what you want to do with these, for my 2 cents I'm not so keen on these additions, especially given we'd want to discourage their use anyway. |
Sure, I'm aware of that. But this is different; it's not about comparing an instance with a class. Also, there are perfectly valid reasons for needing to do introspection on the class hierarchy. For instance, I submitted this issue because I built a plugin framework, and in my |
Correct.
Sure, but if anything this is less vague than the existing
I chose those 4 method names in an attempt to be consistent with the distinction made by this existing API, but I'm not wedded to the names; they were just examples for illustration.
No, it's fundamentally different. The receiver of
Not true, for the same reason as above.
What you're talking about already exists in SuperCollider as
However that is fundamentally different the
That's why I italicised "class" in the original report above ;-) |
No, that tests whether something is a direct instance of class, not whether class is its immediate superclass.
Ah, you're right of course, sorry! I stand by my point about the existing way of doing this being pretty trivial though. |
No problem ;-)
But half of my example implementations don't work properly, as explained in the original report ;-) I wrote:
(You can't call |
A primitive would be best. Is there any reason why
returns true? Intuitively I'd think it should. |
Because of the implementation this does return true:
But the semantics of isKindOf suggest the first example should as well. |
Yes; it would change the contract of that method AND require a technique similar to isDescendantClassOf in order to disambiguate, because now 5 and the class Float are both "kindsOf" Number. In addition, someone looking at the code won't be immediately able to tell which of those you intend to test.
isKindOf is a predicate on the type of an object. That is fundamentally different than a predicate on a relation between types. |
I support adding at least the ability to test easily and directly whether one class is in the inheritance tree of another class. The rest I'm not so sure of, since the direct superclass/subclass methods IMO can be expressed more clearly with the actual equality test, and the isAncestorClassOf can be achieved by just flipping the parameters (or am I missing something obvious?). I don't support adding a blanket discouragement; if the docs are going to take an opinion, they should provide cases where use is justified, and an example of how misuse can be remedied through redesign. |
yes, the concept of parallel object and class (Meta something) hierarchies is fundamental, and better not blurred. The ambiguous English semantics of " is kind of" is really the problem here. This basically goes back hundred years, where the difference between element of a set and part of a set was just discovered. |
could be |
Well, yes. There is certainly a precedent for methods that respond to different argument types. @brianlheim I'm not sure there's really a 'contract' in the sense that you mean. But probably Julian is right about the usefulness of the distinction. |
this is at least clear. |
'documented meaning' then? let's not split hairs like this, it would be a very significant change to what the method does. |
Yes, agreed! If memory serves I think I wrote that documentation, so it’s all my fault anyway! ;-)
… On 13 Jan 2018, at 16:55, Brian Heim ***@***.***> wrote:
I'm not sure there's really a 'contract' in the sense that you mean
'documented meaning' then? let's not split hairs like this, it would be a very significant change to what the method does.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
We already have
isKindOf
andisMemberOf
for comparing an instance with a potential superclass, but we should also be able to cleanly compare a class with a potential superclass or subclass, e.g. something like these (untested):except without breaking when fed
Object
as one of the two inputs like the last two of these would, becauseObject.superclasses
isnil
. Similar breakage would occur if the implementations instead usedsubclasses
andallSubclasses
.The text was updated successfully, but these errors were encountered: