Skip to content

Add NodeBuilder for node instantiation #158

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

Merged
merged 21 commits into from
May 30, 2022

Conversation

Soya-Onishi
Copy link
Contributor

Close #157

This PR add builder only for replacing current Node constructor, and still not implement node options for #142.
Current implmentation still remain node constructor.
However, after builder implementation, does normal constructor have demand?
If no, I'll remove constructor, and I also fix some docs and implementations.

@Soya-Onishi Soya-Onishi marked this pull request as ready for review May 11, 2022 10:14
@Soya-Onishi
Copy link
Contributor Author

As a milestone, current NodeBuilder supports only namespace and no node options are supported.
After this PR is merged, I'll work on node options support.

This PR also has current implementation change.
Methods related to Node instantiation like Context::create_node and Node::new only delegate responsivility for instantiation of Node to NodeBuilder

@nnmm
Copy link
Contributor

nnmm commented May 11, 2022

@Soya-Onishi there seems to have been a mixup with the recently merged PRs, could you rebase it cleanly onto master?

Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I left some initial remarks.

Also, feel free to explicitly request a review on your PRs when they're ready, otherwise it's easy for us to miss them.

For backward compatibility, it is better to retain constructor method
but deperecated.
As for now, constructors only use NodeBuilder.
@Soya-Onishi
Copy link
Contributor Author

Sorry for lack of knowledge about git. Is this form desired commits which @nnmm mentioned?

Soya-Onishi and others added 3 commits May 12, 2022 11:28
That will re-appear when supporting node options
Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality-wise, this looks good to me. I'd only delete the Node::new_with_namespace() and Context::create_node_with_namespace() functions.

However, I think we should aim for making the documentation excellent as well.

  • The "Naming" section of the Node::new_with_namespace() function's docs should probably be moved to the Node struct
  • The NodeBuilder::namespace() function should reference the naming rules for namespaces, and mention that validation only happens later, in the build() function.
  • The NodeBuilder::new() function should do the same for the node name, since it takes the node name as an argument
  • Every function should have an example/doctest. The example from Node::new_with_namespace() can be reused for these.
  • Convenience functions should reference the original functions they're equivalent to (in this case, that's only Context::create_node_builder(), which I've left a suggestion for)

@esteve esteve self-requested a review May 13, 2022 10:49
@esteve
Copy link
Collaborator

esteve commented May 13, 2022

@Soya-Onishi thank you so much for your contribution! 🙂

@nnmm
Copy link
Contributor

nnmm commented May 16, 2022

@Soya-Onishi Seems like there are again some accidental changes from resolving conflicts with master.

@Soya-Onishi
Copy link
Contributor Author

Soya-Onishi commented May 17, 2022

From some searches, I cannot found the way to rebase with clean commit logs, For now, merge is clearner than rebase in this case(conflict appear after creating PR), I think.

@nnmm
Copy link
Contributor

nnmm commented May 17, 2022

@Soya-Onishi That's fine, the commit log doesn't need to be clean since we usually squash when merging.

But if you're interested, I usually simply do "git rebase master" when there are conflicts with master, and if I want to squash things locally, I do "git reset --soft master && git commit" on the branch.

@nnmm
Copy link
Contributor

nnmm commented May 17, 2022

Also, thanks for fixing the error type in the doctests!

@nnmm
Copy link
Contributor

nnmm commented May 18, 2022

@Soya-Onishi Would you be okay with me pushing some documentation improvements directly to this branch (no code changes)? That would be easier than commenting here.

@Soya-Onishi
Copy link
Contributor Author

@nnmm Sure, please push your commits.

@nnmm
Copy link
Contributor

nnmm commented May 19, 2022

@Soya-Onishi Just an update, I didn't manage to do the doc improvements yet, but probably tomorrow.

@nnmm
Copy link
Contributor

nnmm commented May 20, 2022

@Soya-Onishi Done.

From my side, this is now almost good to go. I have three suggestions:

  • Could you create a new file for the node builder (node/builder.rs)? It might require marking a few fields in node/mod.rs as pub(super), but that's okay.
  • Could you swap the arguments to NodeBuilder::new()?
  • We could have a Node::builder(context: &Context, node_name: &str) -> NodeBuilder method instead of NodeBuilder::new(). That is a common pattern because it's easier to discover when looking at the Node struct, and it's also slightly shorter,

@Soya-Onishi
Copy link
Contributor Author

Soya-Onishi commented May 22, 2022

@nnmm Should I swap arguments of Node::new() also?

@nnmm
Copy link
Contributor

nnmm commented May 22, 2022

@nnmm Should I swap arguments of Node::new() also?

Yes, please.

@nnmm
Copy link
Contributor

nnmm commented May 23, 2022

@esteve Could you maybe re-review and see if you feel like you can remove the changes requested status? Then I'd do a final review of documentation.

Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only four small improvements, then this is good to go from my side!

Soya-Onishi and others added 4 commits May 24, 2022 23:14
Co-authored-by: Nikolai Morin <[email protected]>
Co-authored-by: Nikolai Morin <[email protected]>
Co-authored-by: Nikolai Morin <[email protected]>
Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@esteve ptal!

@esteve
Copy link
Collaborator

esteve commented May 30, 2022

@Soya-Onishi thanks for iterating and addressing our feedback!

@esteve esteve merged commit 7daf8cc into ros2-rust:master May 30, 2022
@Soya-Onishi
Copy link
Contributor Author

Thanks for your suggestions and cooperation!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node constructor method become verbose?
4 participants