Re: [go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-29 Thread robert engels
NatsIO which is a pretty major application has this https://www.javadoc.io/doc/io.nats/jnats/2.0.0/io/nats/client/Options.Builder.html This is a pretty good “tutorial” - and I think you can see how it can be applied to parameters or instance creation (e.g. the server instance). see

Re: [go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-29 Thread roger peppe
I'm not familiar with the Builder pattern. Could you provide a good example of its use in a Go package? On Mon, 25 May 2020, 06:25 robert engels, wrote: > I think the Builder pattern is easier than this, and it retains the > property of both ‘config struct’ and ‘multiple args’ versions that the

Re: [go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-25 Thread Amarjeet Anand
Thanks Robert for the nice idea. Using builder pattern to set options didn't come to my mind. Looks really clean. On Mon, 25 May, 2020, 10:55 AM robert engels, wrote: > I think the Builder pattern is easier than this, and it retains the > property of both ‘config struct’ and ‘multiple args’

Re: [go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-24 Thread robert engels
I think the Builder pattern is easier than this, and it retains the property of both ‘config struct’ and ‘multiple args’ versions that the implementation can re-order and validate option in aggregate easier - but most of all is doesn’t pollute that package with top-level public functions. The

Re: [go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-24 Thread Amarjeet Anand
Thanks James for your response and the amazing posts. On Mon, May 25, 2020 at 9:01 AM James wrote: > This reminds me of functional options which I think are used quite widely > for this purpose. > > See > https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis > and >

Re: [go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-24 Thread James
This reminds me of functional options which I think are used quite widely for this purpose. See https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis and https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md On Mon, 25 May 2020 at 14:57, Amarjeet Anand

[go-nuts] Is it acceptable to make the optional parameter as varargs

2020-05-24 Thread Amarjeet Anand
Is it acceptable to make the optional parameter as varargs? I wrote code in my package like ... package backoff func New(options ...Options) *backOff { backOff := defaultBackOff() if len(options) == 0 { return backOff } // override default values if len(options) > 1 {