-
Notifications
You must be signed in to change notification settings - Fork 22
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 Vertex options hybrid #92
Conversation
This way we can still have the mandatory options directly in the embedding func constructor, making it more similar to the existing ones.
To make clear that the created struct is prefilled with default values
As a non-newcomer, I still think it's not that intuitive. With a struct you can see right-away which options are available (the fields of that struct), even just by hovering over it in your IDE. Variadic options always have to be looked up - but I like the function signature when using them, especially when adding them to an existing project where they won't break backwards compatibility. My first take with the builder pattern was: "I'm going to pull the config definition out of the function call, because it's going to grow quite large and make it unreadable." - That's why I put the whole config into the config struct. Now this probably doesn't help you a lot other than saying, that both #92 and #93 are fine and better than my original implementation :) |
And while from an IDE perspective the options struct is better (immediately visible options), in the rendered Godoc it's the other way around: With variadic functions all And with the options struct, as long as it's not exported, it's not visible at all: And if the options struct is exported, people may use that instead of Actually, as long as the options struct is not exported, it's not even as clear cut in the IDE:
One thing worth noting is that we already have Or maybe a breaking change is required anyway, if for example we want to remove the optional "where" and "whereDocument" filters from the I'll think about everything a bit more. 🤔 |
I chose the variadic functions for now, to have something to move on. I'm releasing a new version |
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.
F
As per #91 (comment), this PR is a suggestion to do kind of a hybrid for the options. We use mandatory parameters directly in the constructor function, but then instead of variadic functions we have one struct for optional configuration that can be adjusted with a fluent API (
opts.With...().With...()
).Variadic functions are very popular and common in widely used libraries (e.g. grpc-go), and have the benefit of not requiring the last parameter in case you're fine with default values. Some downsides are that passing functions instead of a struct can be less intuitive (maybe just for Go newcomers), as well as that each
With
function for an optional option is then a global package member.TBH I'm undecided which is best. This PR is just a suggestion and open for discussion.
The alternative is to revert to variadic functions, PR here: #93