|
|
|
|
|
by l_t
2310 days ago
|
|
I like dependency injection even when I'm not writing tests (which I usually skip for side-projects.) I find it natural and convenient to think about "What dependencies on other parts of the system does this code have?" Expressing those dependencies explicitly feels like it reduces complexity, not adds it. But, I'm not talking about pulling in a big fancy DI framework, just making dependencies explicit in your function/class parameters. I will say that DI is sometimes used as a tool in overly-abstracted systems. An example that comes to mind is the ASP.NET MVC framework -- with DI and inheritance, literally any behavior can be overridden in fairly opaque ways. Trying to suss out the concrete behavior details is like swimming in quicksand. (Or it used to be that way, haven't touched ASP.NET in a while.) As an aside -- I'm curious about your programming language of choice. I think DI is a lot more useful in some PLs than others. For example, I find JS code often uses imports to create complex graphs of implicit dependencies, and DI can help tame that complexity. But for other PLs like Python or Clojure, I basically don't use DI at all. |
|
Now Java and C# are different because they are compiled. You need a DI tool to do dynamic dispatch if you want to mock.