| ▲ | dkersten 2 days ago | |
I hate that singleton is first. Singletons are just globals with extra steps, and have all the same problems globals have, just people (especially juniors) think they somehow are better. In reality they’re worse because they conflate global access with enforced single instance. You almost never need to enforce a single instance. If you only want one of something, then create only one. Don’t enforce it unless it’s critical that there’s only one. Loggers are often given as an example of a “good” singleton and yet we often need multiple loggers for things like audit logs, or separating log types. Instead of singletons, use dependency injection, use context objects, use service locators, or… just use globals and accept that they come with downsides instead of hiding behind the false sense of code quality that is a singleton. | ||
| ▲ | 2 days ago | parent [-] | |
| [deleted] | ||