[go-nuts] Re: constructors vs lazy initialization

2018-03-11 Thread matthewjuran
> > I prefer the later when possible because it enables callers to use the > zero value of a type without explicit initialisation. Two great standard library examples of this are sync.Mutex / sync.RWMutex and bytes.Buffer / strings.Builder. Matt On Saturday, March 3, 2018 at 9:20:11 PM

[go-nuts] Re: constructors vs lazy initialization

2018-03-11 Thread snmed
But this is only working as long as you do not need any services or dependencies. And in that case i would really appreciate if the language natively supports a nil check on method parameters at compile time. For all cases where nil is a valid value, the language needs a marker to allow such

[go-nuts] Re: constructors vs lazy initialization

2018-03-05 Thread Chris Hopkins
I would say Lazy initialisation should build code that is more robust - I can think of few applications where that is not worth the price. So as a rule I agree Lazy is a good place to start unless you have a good reason not to. I also understood it was more idiomatic. In terms of

[go-nuts] Re: constructors vs lazy initialization

2018-03-03 Thread Dave Cheney
I prefer the later when possible because it enables callers to use the zero value of a type without explicit initialisation. On Sunday, 4 March 2018 11:37:43 UTC+11, Anmol Sethi wrote: > > How do you guys choose between constructors and lazy initialization? > > For example. > > Struct