|
|
|
|
|
by codahale
3988 days ago
|
|
It’s worth noting that not only do you need to synchronize access to the singleton, you need to synchronize access to the singleton’s state as well. And even if you manage that at a fine-grained layer, you’re still setting yourself up for all the problems associated with singletons: http://c2.com/cgi/wiki?SingletonsAreEvil. If you have a bunch of immutable state, then build unexported package variables in the package’s `init` func and export funcs which use those variables. If you have a bunch of mutable state, then don’t use a singleton. |
|