-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Proposal] Refactor resolve
fn to be more flexible and extensible
#2775
base: develop
Are you sure you want to change the base?
[Proposal] Refactor resolve
fn to be more flexible and extensible
#2775
Conversation
Move node-specific resolution logic from `resolve` function to each node type class to allow extending / changing the behaviour in custom types, as well as cleaning up the code a bit
Thanks, I quite like this approach, splitting the functionality per node class. Only downside is that this makes all Node classes a bit more fat again, and when you don't need the functionality you still have to load the full classes. An alternative would be to add a callback handler to the @gwhitney do you have any thoughts on this? |
Well, at first glance, to get the same effect/ability that Matt is after while avoiding the drawbacks of adding code to every Node class that will only be used by clients that want to do
I think this approach has a much lighter footprint on existing mathjs code, will all work, and accomplishes everything Matt was aiming for. That said, I haven't actually tried it, so there could be speedbumps I am not seeing... Hope this helps. |
Yes, that is an issue indeed, it makes the Node classes more bloated, and that code is only relevant for people using the So, an other approach could indeed be making the (Glen I think you mean |
Indeed, fixed. |
@josdejong Yeah those are definitely other options, I'm not stuck on my implementation at all. I guess I'm just still not that familiar with typed-function.
@gwhitney Could you give me a pseudo-code example of how the
Could also you give me a pseudo-code example of what |
This refactor allows custom resolve methods for different node types or for newly added node types, as an alternative to josdejong#2775. Adds a test that demonstrates the creationg of a (stub) IntervalNode, as if you were doing interval arithmetic, say, with a custom resolve method for the new type.
Well the best way to describe is to do, so I can go one better and just provide #2801 that implements my suggestion. And the new test I added for the use case you propose should provide a pretty good outline of how to do what you want to do. Let us know if it works for you. |
Thanks Glen for working out a demonstration in #2801. I quite like that the Node classes are not aware of anything related to An other idea: we can go with the approach of Matt, but instead of basing it on methods @mattvague what are your thoughts? |
The "overriding three signatures" thing is because typed-function doesn't allow optional arguments. I don't see why this architecture/leveraged use of typed-function should be penalized because of that. But based on your comment, the implementations can be rearranged so that there are single generic forwarders with undifferentiated Node arguments and only one "workhorse" for each Node subtype. Shall I push a commit with that refactor so you all can look? (Also I can fix the doc error.) |
OK, I went ahead and rearranged the implementations in #2801 so that to add any new node type, you only have to supply the |
😎 nice, these last tweaks in your PR take away my argument against your proposed solution Glen. I think #2801 is a perfectly good solution now, and going for this approach or these alternative ideas I proposed is mostly a matter of personal preference. @mattvague any feedback? |
Problem
Currently, all of the logic for deciding how resolution works lives in the global
resolve
function. This means that it's impossible to change the resolution behaviour on custom Node subclasses.Solution
Move node-specific resolution logic from
resolve
function to each node type class. This has the benefits ofMotivation
In my app, I'd like to implement a custom node type called
RandomValueNode
that replaces itself with aConstantNode
with a random value when it's tree is resolved, however the current implementation of resolve makes that impossible.@josdejong thoughts on this idea? If you like it I'll go and add unit tests for each node type
resolve
method and add some docs.