Kent Rancourt
1 min readFeb 17, 2020

--

A New function is the kind of initializer that was mentioned earlier in the post. the problem with it is that you need to go to great lengths to ensure/enforce your structs being created ONLY via the initializer (i.e. only initialized in a valid state). A common pattern has been initializers that return an exported interface, while the struct that fulfills that interface is unexported. That makes it impossible that initialize things in an invalid state because you HAVE to use the initializer… I happen to like this pattern, but I believe it’s the exact sort of “intricacy” that the author was trying to avoid with the “make the zero value useful” pattern.

--

--

Kent Rancourt
Kent Rancourt

Written by Kent Rancourt

Kent is a founding engineer at Akuity, working primarily with Kubernetes, Argo CD, and other open source projects.

No responses yet