-
Notifications
You must be signed in to change notification settings - Fork 311
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 findComponent() private? #1025
Comments
I recently advocated for making it public (I thought it was protected or private). I would like two public methods:
I think there are good use cases for both of these public methods. |
Currently, the doxygen for I would expect a user to try |
If I want to check if a component try {
getComponent("foo");
} catch (...) {
...
} or auto* foo = findComponent("foo");
if (foo != nullptr) {
...
} The latter is cleaner.
I think this is more how @aseth1 had it originally and I was opposed to it. You want one method that gets the component you asked for (unambiguously), and a separate method that will search for a component. Those are different requests, and so I think it is cleaner to have separate methods. It'd be better to chat in person I think. |
I think this clarifies our disagreement. IMO, the user won't care what OpenSim needs to do behind the scenes to get the Component. Just doing the search and gently suggesting that a direct "get" would be faster (and perhaps even printing out the full path for the user) would be much friendlier than throwing an exception and telling the user the Component doesn't exist on the specified path. We already have "get" and "upd" prefixes to deal with; is it necessary to add a "find" into the mix? The cognitive load is already high with templatized methods, "Connector" vs. "Connectee", etc. If the concern is about determining whether a Component exists, it seems like a class OSIMSIMULATION_API Model : public ModelComponent {
...
public:
static Component& NOT_FOUND; //if this sort of thing would work...
... Happy to discuss in more detail. |
I'm tempted to respond but I would prefer to talk in person. I do think that a |
Fixed by #1030. |
I think it's confusing to present users with both
getComponent()
andfindComponent()
. These methods can be used (almost) interchangeably if the path is known ("almost" because one returns a reference and the other returns a pointer). I think it would be preferable to have a singlegetComponent()
method that callsfindComponent()
if necessary.The text was updated successfully, but these errors were encountered: