-
Notifications
You must be signed in to change notification settings - Fork 4
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
WISH: replace class-of with a word-matching routine #102
Comments
Perhaps |
|
If we talk about duck-typing, we only care about functionality, not data/state, don't we? In the case you provided, I'd say object 1 is a functional descendant of object 2, because it includes it's functionality, which is NO functionality :-) |
OK ;) But think about the data model. object 1 extends data model of object 2. |
Another more flexible option would be to check presence of all words of one object in the second object (regardless of their order), but this will be slower due to comparisons becoming hash lookups. It's more into the field of multiple-inheritance than just |
Seems there are conflicting goals: 1) flexible, 2) lighting fast. I agree that Duck Typing means we care about compatibility, not what prototype(s) might have been used. This also plays against speed. Wording is tricky too, and I lean toward Two thoughts:
Since all they return is a
|
True. Objects already possess a hash table. Setup code may be done only once: Lookup code should be repeated for every word, but they're pretty light - should be 1-2 iterations on average, no hashing done. Plus it will iterate until the first failed lookup, making negative cases even quicker: Red's baseline speed (on my laptop) is about 40-50ns per token. |
On |
Thanks for the numbers, which are like candy to me. Actually, better because I don't eat much candy. The most important thing is correctness in the context of use. @dockimbel needs to weigh in on his original design goal for |
The great thing about code that might be too slow is that we'll find out when it is, and can optimize it then. As long as we don't botch the interface to things too badly, I'm all for slow code. |
Related issue red/red#4269. |
Work on Spaces has opened a new dimension to this topic. Yes, as a user of the object, duck-typing is enough for me to interact with it.
For this resource economy use case, two seemingly identical ducks may belong to different classes and vary in their checks or on-change handlers. For example, general
If we had language (R/S) support for features of #132 then I suppose it could be fast enough and not require too much RAM as long as on-change body is referenced, not copied. Then it could be supported on per-object granularity, and there would be no need for such non-duck-like classes. It would still require though per object word: a typeset and a few references to checking code, and the checking code itself, so still a few times the RAM a simple hash-backed object takes, so doesn't seem like a sound option. Maybe if we had both simple and typed objects as different types, or if simple object would be promoted to typed one on demand, so users would have a choice, that would be more acceptable. Still doesn't grab me yet. Having a hidden class name or reference seems like a better solution. So this is deeper than I thought. Basically it comes down to two interpretations: "does it behave like 'class?" or "does it work internally as 'class?" (is this duck live or robotic?). |
Also a bit of an issue here is that
|
class-of
has proven itself to be a design you can't rely on, see red/red#4396It will still work for objects you never expect to be extended, but I like much more Python's "if it quacks like a duck, it must be a duck" philosophy because it's reliable. It boils down to this:
It works because
make proto new
addsnew
words after the words of theproto
.Problem with this mezz is that both
words-of
calls allocate new blocks, so one can easily overload the GC.Another problem is that this operation is supposed to be lightning fast like, because it may be used in
on-deep-change*
, in timers, in event filters - time critical places.I suggest we implement a routine version of it and ship it with Red runtime.
There can be naming variants though..
parent-of child parent
vschild-of parent child
child child-of parent
vsparent parent-of child
parent-of?
orchild-of?
parent?
andchild?
based-on
,descendant-of
,prototype-of
,model-of
etc.What name and type (func/op) should work better?
The text was updated successfully, but these errors were encountered: