Hacker News new | ask | show | jobs
by hendzen 3991 days ago
This post is chock-full of antipatterns. Both the singleton pattern and double checked locking should be avoided.
1 comments

Yea it's easy enough to use dependency injection to satisfy these supposedly "global" requirements. About the only global state I can tolerate is read-only constants, but even then you are much better off with DI just because of testing.
How do handle configuration? Your program starts up, generates some settings, then those need to be shared across all threads to avoid incurring the cost of regenerating during every call to a function.
But in that case config values are to be treated as constants (read only). You don't have concurrency issues for code that doesn't change.
DI is an antipattern.
who told you that? you'd better not listen to that guy anymore.
What are better alternatives? Service locator?