DI: ☺️
DI frameworks: 😒
I just DI all the time, it’s called a constructor.
XML is the second worst programming language ever created by humans
I’m gonna need a bell curve hooded figure meme template of this comment, this is comedy gold.
It’s a markup language, not a programming language.
Like yaml/toml
The one benefit of toml is that nobody creates a programing language over it.
The one benefit of toml is that nobody creates a programing language over it.
Heh. Any day though, right? I can’t wait to see an excited presentation on code-free coding in YAML…
Github Actions have entered the chat.
Thanks. I hate that you’re right.
Whoosh
Seriously though, spring configurations are written in XML and you create variables, call functions, and have control flow. Effectively turning XML into a horrible twisted shadow of a programming language.
All in the name of “configurability” through dependency injection.
Tell that to SOAP.
Yo dawg, I heard you like XML over HTTP so I put XML over HTTP in your XML over HTTP.
Standard shitpost and then out of nowhere “Hello inject me with beans please”
WHY IS IT SO FUNNY
I inject myself with beans every morning, usually French press
Hello inject me with beans please
not again
Yeah, I’d rather get injeancted with beans.
Say what you want about DI frameworks, but if I have to remove another fucking global variable so I can write a test, I’m going to cut a bitch.
Dependency injection is so much worse. Oh, hey, where’d this value come from? Giant blob of opaque reflection code.
It can be used in bad ways, but if it’s used in the right way you should never have the situation you just described.
I’m not exactly sure what you mean. Doesn’t all dependency injection work the way I described?
Without being familiar with the framework, you can’t trace your way from the class getting injected into to the configuration, even if you’re experienced with the language.
I don’t think so. When I’ve seen it done it’s usually not been random values injected (except when those values are secret keys which should absolutely not be stored in code to begin with), it’s usually injecting a service. Another class, usually with a name that makes it easy to trace down. Like if you’re building an
OrderService
, that might take as a dependency anIProductService
, which would have injected into it the classProductService
(personally, I don’t like the Hungarian notation that C# uses, but it’s a convention and my preference for sticking to strong conventions for the sake of consistency outweighs my distaste for Hungarian notation). That’s easy to find, and in fact your IDE can probably take you straight to it from theOrderService
’s constructor.I’m using value in the loosest sense, like how all objects are values.
So now if you have three implementations of
IProductService
, how do you know which one is configured?It’s easy to imagine a hypothetical way that could lead to problems. But in all the code I’ve worked with, either that scenario is avoided entirely, or other context makes it absolutely clear which
IProductService
is being used.
I think this might be the first of these I’ve seen where pretty much all the comments are just agreement.
semi-related, Rich Hickey’s rant about HTTPServletRequest
It came over the wire as text! How did you turn it into that?
Gold.
…and the wheel turns again…
We’re struggling to deal with climate change and these selfish developers can think of nothing except building more factories. This is a global issue, we need a global solution: eschew factories and services for defining everything globally.
My favourite take on DI is this set of articles from like 12 years ago, written by a guy who has written the first DI framework for Unity, on which are the currently popular ones, such as Zenject, based on.
The first two articles are pretty basic, explaining his reasoning and why it’s such a cool concept and way forward.
Then, there’s this update:
Followed by more articles about why he thinks it was a mistake, and he no longer recommends or uses DI in Unity in favor of manual dependency injection. And I kind of agree - his main reasoning is that it’s really easy for unnecessary dependencies to sneak up into your code-base, since it’s really easy to just write another [Inject] without a second thought and be done with it.
However, with manual dependency injection through constructor parameters, you will take a step back when you’re adding 11th parameter to the constructor, and will take a moment to think whether there’s really no other better way. Of course, this should not be an relevant issue with experienced programmers, but it’s not as inherently obvious you’re doing something potentially wrong, when you just add another [Inject], when compared to adding another constructor parameter.
Exactly. Dependency injection is good; if you need a framework to do it, you’re probably doing it wrong; if your framework is too magical, you’re probably not even doing it at all anymore.
Why yes, I would like my stack traces to make no ffing sense! I’m so glad you asked.
I’ll never plaster the back of my car with stickers that all proclaim the same things in ALL CAPS.
But if I was going to…
It would pretty much match this meme.
As an audio engineer, I was very confused about what this had to do with Direct Injection for a second.
Thank you, I’m not alone! :)
Urgh. I just sicked in my mouth.
Die in a hole DI frameworks.
I already have an injection ‘framework’ it’s called a constructor. I already have a factory it’s called
new
Tell me more about these beans