-
Notifications
You must be signed in to change notification settings - Fork 383
Update builder.md #433
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
base: main
Are you sure you want to change the base?
Update builder.md #433
Conversation
Cite advantage about code extension use-case and the fact that Rust does not support default values for function parameters.
@@ -73,6 +73,9 @@ Prevents proliferation of constructors. | |||
|
|||
Can be used for one-liner initialisation as well as more complex construction. | |||
|
|||
When the target struct is updated with new fields, the builder can be updated | |||
to leave client code correct without changes. |
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 not sure what this means
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.
Imagine you have a custom type (the target struct) that you want to extend with new behaviour. You would like to add new behaviour and use it in new code, without modifying existing legacies. Since the builder pattern encapsulates the construction logic, it's possible to update the builder so that new fields can be used in new code while safely ignored in older usages.
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.
oh, ok, maybe we should rephrase "correct without changes" with "backwards compatible"?
Also, we haven't defined what the target struct is. Maybe we can find a better name for it.
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.
Also, I would rephrase as the following to follow the "active form" instead of passive:
When you add new fields to the target struct, you can update the builder to leave client code backwards compatible.
many other languages because Rust lacks overloading and default values for | ||
function parameters. Since you can only have a single method with a given name, | ||
having multiple constructors is less nice in Rust than in C++, Java, or others. |
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.
this change looks good 👍
Cite advantage about code extension use-case and the fact that Rust does not support default values for function parameters.