3 ms·
Hard disagree. Singleton is a tool, and like any tool it has trade-offs. Singletons help you target a very specific, useful time in your application: after it's
by javajosh 5y ago
Hard disagree. Singleton is a tool, and like any tool it has trade-offs. Singletons help you target a very specific, useful time in your application: after it's compiled, but before it's serving requests. You can call this the "initialization time". Within this time, singletons help you organize the one-off components of your application - canonincally, things like connection/thread pools.
But hey, thanks for the hot take.
- cr__ 5y agoWhy not explicitly initialize the one-off components and pass them to the other parts of the system that need them as arguments so the system is testable and dependencies are clear? (I know why, generally—low-expressivity languages make it nightmarish to actually do this.)
- nedbat 5y agoIf you need just one, make just one. Why should the class enforce it?