logoalt Hacker News

Aeolunyesterday at 2:36 PM2 repliesview on HN

When applied without thinking about why. Yes.

Except dependency injection. I really can’t imagine why you’d ever not use that. I suppose it’s possible to overuse, but you’d still have better code than without. Certainly more testable code.


Replies

Scarblacyesterday at 3:04 PM

Because code becomes harder to understand.

With direct dependencies, if you are trying to understand some code that calls some function and what it does exactly isn't completely obvious, you can press a button to go to it, understand it, and come back.

With dependency injection it depends on what is going to be inserted during runtime, so you can't.

show 1 reply
layer8yesterday at 3:25 PM

Unless you mean just regular constructor parameters, dependency injection in the sense of a runtime dependency injection framework is the one thing I try to avoid like the plague.

show 1 reply