-
Notifications
You must be signed in to change notification settings - Fork 6
Make InfoTreeGenerator Prioritized #92
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
Make InfoTreeGenerator Prioritized #92
Conversation
This allows us to sort them, and find the highest-priority
ctrueden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 OK!
|
|
||
| @Override | ||
| default double getPriority() { | ||
| return Priority.NORMAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gselzer Make it makes sense for the Prioritized interface itself to have this default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda like the fact that it doesn't - it makes you think about what the priority should be amongst the existing implementations. And there's the fact that this was the smallest necessary change to avoid our bug.
| if (suitableGenerators.size() > 1) throw new IllegalArgumentException( | ||
| "Signature " + signature + | ||
| " is able to be reified by multiple generators: " + suitableGenerators); | ||
| return suitableGenerators.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the top two InfoTreeGenerator instances have the same priority? Should we fail fast? (I don't have an opinion, just pointing out that right now, on ties, one of them arbitrarily wins.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to say YAGNI for now
@ctrueden noted here that current logic could throw errors if there are multiple InfoTreeGenerators that match a particular Op signature, and outlined two choices:
InfoTreeGenerator, so people can't implement it, and hardcode the priority.InfoTreeGenerators could reify the signature, choose the highest priority.This PR chooses option 2 as it is the less-API-breaking change, and because a priority-based system makes more sense than encoding an ordering by e.g. position in a
List. This PR doesn't hideInfoTreeGenerator, but it also does not prevent us doing so in the future, and I'm not particularly against hiding it until we decide we need it.Hiding
InfoTreeGeneratorwould be as simple as moving it to a non-exported package. I still believe we'd want to service-load the implementations, as otherwise we'd probably introduce sub-package dependencies, failing the build, but that should still work if we move the package of theInfoTreeGenerator.Closes scijava/scijava#87