News for hackers. Stuff that matters.
Re:Dependency injection is dynamic scoping in disguise by glun on Thursday October 31, 2019 @05:38AM (#21407028)
Author here. After posting this to reddit I realized that the original title is wrong, and poorly reflects the actual point I'm trying to make. Dependency injection is not dynamic scoping, but the latter can be used to achieve the former. I'm drafting an update to better reflect this. I'm also going to pull out reader monads and env passing into separate sections and give reader monads a better treatment in general.
Re:Dependency injection is dynamic scoping in disguise by eternalban on Thursday October 31, 2019 @07:53AM (#21407703)
The 'Env' is typically called 'Context'.

These mechanisms are addressing functional requirements in component oriented systems, but in the industry have been misunderstood and misused to satisfy testing requirements.

And if one is not doing pervasive component reuse across multiple systems and projects, the on-off usage of DI is of course completely over-engineered and likely a poor design decision.

Re:Dependency injection is dynamic scoping in disguise by mrec on Thursday October 31, 2019 @10:20AM (#21409080)
And one obvious refinement of the `Env`/`Context` God-dependency pattern is to have it implement a bunch of fine-grained interfaces for subsets of the dependencies it aggregates, so that you can both reduce plumbing (only one thing to inject) and still make it clear which specific dependencies a given call might use.
Re:Dependency injection is dynamic scoping in disguise by DaiPlusPlus on Thursday October 31, 2019 @06:32PM (#21414461)
How would you manage scoped lifetimes and transient objects using the Env/Context pattern?
Re:Dependency injection is dynamic scoping in disguise by eternalban on Thursday November 07, 2019 @05:58PM (#21478194)
I creatd a minimal framework in C++ in mid '90s around the concept of Contextual Objects. Child contexts can be used to affect life-cycle scopes. In this approach, the virtual construct of a 'containment context' allows for managed life-cycles, at an aggregate level. Delete the context and all child objects (recursively) are deleted as well.
Re:Dependency injection is dynamic scoping in disguise by mcherm on Thursday October 31, 2019 @07:03AM (#21407454)
I really liked this essay -- I found it very clearly explained and it pointed out something I ought to have known but somehow had never previously realized.

My only complaint is that when I went to go read through the other articles on your blog and perhaps add it to my RSS feed there weren't any other articles! This wasn't the first thing you have written... is there a place I can read some of the others?

Re:Dependency injection is dynamic scoping in disguise by glun on Thursday October 31, 2019 @07:27AM (#21407571)
Thank you. This warms my heart to hear. However, this is the first thing Ive written outside of isolated reddit comments. But I do have a backlog with a few articles that I have mapped out but havent gotten around to writing yet.
Re:Dependency injection is dynamic scoping in disguise by HereBeBeasties on Thursday October 31, 2019 @09:38AM (#21408559)
Please do. IMO, this was very well written, well-paced and interesting.
Re:Dependency injection is dynamic scoping in disguise by mercer on Thursday October 31, 2019 @02:34PM (#21412109)
Seconding the sibling comment that I'd love to read more of your posts, and the most likely way I'll notice a new post is if the RSS feed works :).
Re:Dependency injection is dynamic scoping in disguise by z3t4 on Friday November 01, 2019 @05:38AM (#21417274)
If the title was less click-baity I probably wouldn't have read your article. The article itself was perfect. It was short enough, and it was informative enough. If you want to expand on a subject it's probably better to make a new URL and link to it, or if good articles already exist, link to those.
Re:Dependency injection is dynamic scoping in disguise by ScottBurson on Saturday November 02, 2019 @02:39PM (#21429238)
There's an example of dynamically scoped variables that will be familiar to almost everybody: environment variables, which are passed dynamically across program invocations.
Re:Dependency injection is dynamic scoping in disguise by moljac024 on Friday November 01, 2019 @07:14AM (#21417664)
Can you share a link to the reddit discussion? I tried searching but I couldn't find the post.
Re:Dependency injection is dynamic scoping in disguise by eru on Friday November 01, 2019 @06:12AM (#21417392)
I like that the examples were in a range of different languages.

Not sure how well that works for other people, but I think the way you wrote it makes them understandable even for eg people who don't really know Java.

Re:Dependency injection is dynamic scoping in disguise by Gibbon1 on Thursday October 31, 2019 @05:40PM (#21413988)
Your essay reminded me of the local function extension in gcc. A local function has access to the variables in scope when it was defined.
Re:Dependency injection is dynamic scoping in disguise by inetknght on Thursday October 31, 2019 @06:58PM (#21414636)
> Author here.

Can you make it so your site uses HTTPS?

Can you make it so it doesn't just load an frame pointing to Github.io?

Both combined seem very sketchy to me.

Re:Dependency injection is dynamic scoping in disguise by donw on Thursday October 31, 2019 @05:54AM (#21407097)
Good on you for coming here to clarify! :)