-
Notifications
You must be signed in to change notification settings - Fork 357
Export built-in impls of Value and corresponding new funcs #432
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: master
Are you sure you want to change the base?
Conversation
This encourages reuse, making it possible for user to for example dynamically create a []*Flag and add them using (*Flagset) AddFlag. Closes spf13#334 Signed-off-by: Daniel Lublin <[email protected]>
While I, on the surface, understand why this is useful to export, I think we should make an effort to make sure that the API of this library doesn't grow more than necessary, and that users who want to use these features get the help they need to do it correctly. With those points in mind, I have a few questions and requests for this change:
|
Yes I think this change is feasible, since API user controls the "storage container" for the value, which they pass into the "constructor" like for example Will have a look at it. Tentative comment for the (bool) constructor, what do you think?
|
Those docs look OK to me from the perspective of someone who knows the implementation details under the hood, but it's a little unclear to me based on just those sentences why I need to pass both a value and a pointer, especially if one will be set to the other. Does that indicate a smell in the API? 🤔 |
I agree totally! It's really hard to describe to somebody uninitiated what's happening there. That |
I think one big reason for the current API having the default value and the pointer to the storage as separate entities is because there are the BoolVar/BoolVarP/etc type of funcs that take that pointer as a parameter, and the Bool/BoolP/etc type of funcs that returns the storage pointer. Then both these types end up defining a But now that we want to allow user to craft Also, if we would export |
I think so, but it's not cleat to me why, then, we don't just tell the user to set the pointer to the default value themselves prior to calling I wonder if, instead of plainly exposing the |
We ultimately want to allow user to craft Flag struct on their own, as much as possible. I'm guessing you mean something like the following (possibly skipping the
I also considered the signature |
Another attempt at documenting an exported
|
Yeah, what you're saying makes sense. Thanks for indulging me and experimenting a bit! I took a deeper look at the existing function signatures and tried to come up with something that rhymed with them, but couldn't really produce anything much better than what you're proposing here, so I'm gonna say this is OK. I like the docs you proposed in your last comment much better! Nice work! With docs like that on all exported functions, as well as a small section in the Readme about when and how to use them, I think this is good to go! |
Yes I think that could make sense. I looked very quickly at the aged PR from @mmatczuk , and from what I gather, even only implementing the generic |
This encourages reuse, making it possible for user to for example dynamically create a []*Flag and add them using (*Flagset) AddFlag.
Closes #334