3 ms·
"I’ve never seen a bug from someone overwriting a global variable like this, that is intended to be immutable." It can cause headaches in test code (where deve
by sidlls 4y ago
"I’ve never seen a bug from someone overwriting a global variable like this, that is intended to be immutable."
It can cause headaches in test code (where developers try to override the package variable value for test cases, and forget to restore/change it back when done, etc., i.e. they engage in bad practices that I shouldn't have to catch in a PR). It can easily cause production applications to blow up unexpectedly when the variable is changed in a function and that mistake passes through all the tests and the PRs. This practice is one of the worst in the go community, in my opinion.
The first time I saw these package level globals in go code I cringed. It is an absolutely terrible design decision to not have package level immutables that aren't PODs.
- catlifeonmars 4y ago> It is an absolutely terrible design decision to not have package level immutables that aren’t PODs. FWIW here is a proposal to expand const in Go: https://github.com/golang/go/issues/21130 https://github.com/golang/go/issues/21130