>
> 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 UTC-6
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 cas
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 reading/debugg
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 constructor