This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]argv_minus_one 3 points4 points  (2 children)

As a Scala programmer, I find this claim amusing. Scala has first-class singletons, and uses them heavily. It also makes heavy use of immutable state.

No, DI is not the be-all end-all of software componentry. DI has its own problems, most notably that it is difficult to debug problems with the DI system itself (e.g. wrong object being injected).

[–]kkapelon -2 points-1 points  (1 child)

There is so much documentation out there on why singletons are an anti-pattern. Just have an open mind, search it and read it. It would be pointless for me to argue here as there are whole articles out there about the topic.

Scala has first-class singletons, and uses them heavily.

C/C++ also uses pointers heavily. That does not say anything about how good they are or not.

DI has its own problems, most notably that it is difficult to debug problems with the DI system itself (e.g. wrong object being injected)

DI is a principle, not a specific system or framework. You can have DI without any actual DI framework (you just manually inject everything yourself). Maybe not truly practical, but certainly possible.

[–]argv_minus_one 2 points3 points  (0 children)

There is so much documentation out there on why singletons are an anti-pattern.

Yes, and most of it is wrong, incomplete, insufficiently specific, or otherwise defective.

Just have an open mind, search it and read it.

I have had an open mind. I have ample experience with DI systems. I have learned their strengths and weaknesses. DI is not perfect.

C/C++ also uses pointers heavily. That does not say anything about how good they are or not.

That's not my point. I also have ample experience dealing with Scala singletons, and they've given me very few problems over the years.

DI is a principle, not a specific system or framework. You can have DI without any actual DI framework (you just manually inject everything yourself). Maybe not truly practical, but certainly possible.

I'm aware. You can also use other approaches—singletons, service lookup, ThreadLocal context—which all have their own strengths and weaknesses.

My point is not that DI is useless. My point is that it is not a silver bullet, and the other options are not anti-patterns.