Hacker News new | ask | show | jobs
by glun 2418 days ago
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.
9 comments

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.

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.
How would you manage scoped lifetimes and transient objects using the Env/Context pattern?
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.
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?

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.
Please do. IMO, this was very well written, well-paced and interesting.
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 :).
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.
There's an example of dynamically scoped variables that will be familiar to almost everybody: environment variables, which are passed dynamically across program invocations.
Can you share a link to the reddit discussion? I tried searching but I couldn't find the post.
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.

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.
> 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.

Good on you for coming here to clarify! :)