top | item 38103894

(no title)

jbjohns | 2 years ago

Why would Rust need a Dependency Injection framework? It's functional, no? I really hope drifting OO practitioners don't wreck the language putting a bunch of OO stuff that is better done in functional programming.

discuss

order

pie_flavor|2 years ago

It is imperative/procedural, and programming paradigm has nothing to do with DI, which is about automatic generation of certain function parameters.

jbjohns|2 years ago

It's not automatically generated though, it's just specified somewhere else. This is what makes OO projects so hard to read from the outside: you first need to figure out what thing is having an effect on what. In a proper functional style I can go to main and follow everything from there.

As someone else said, if you have some kind of interface to "mock" you can just make this a parameter to a function and pass in the "mock" versions for tests and the regular one for the real program (or select from a set of them based on some parameter or something). A framework would just mean I can't just read from main, I'll have to figure out which DI framework is being used, where that is configured and what things effect its decision making. I see why we ended up doing this in OO but I really don't see the benefit anymore in functional programming with the more direct (and no less flexible) approach.