Kent Rancourt
1 min readJan 13, 2019

--

Good question.

To be honest, hopefully without offending anyone, I don’t believe the section of the wiki that you referenced is written very well. There is a snippet of code there that looks very similar to what I have suggested, with a comment in it saying “DON’T DO IT,” but for full context, you need to scroll back a bit to discover that they are saying don’t do that (only?) for the sake of allowing consumers to mock out the interface for test purposes. The code they go on to cite as what you shouldn’t and should do isn’t explained well, so I’ll be honest in saying their point may actually have been lost on me. Whatever that point may have been, it’s not applicable to the case I presented because my motivations had nothing to do with tests or mocks. My motivation was, instead, to guarantee execution of initialization logic for my user-defined type. There’s no other way I know of to accomplish that in Go, so I stand by this pattern — or I stand by it specifically with respect to the motivation I described.

I hope this answers your question.

--

--

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.

Responses (1)