News for hackers. Stuff that matters.
Re:Dependency Injection is a Virtue by Peaker on Monday January 07, 2013 @06:46AM (#5020565)
Yes, you pass in Random, and file streams.

If you need to pass the same set of multiple things to multiple functions, you declare a type that represents all these arguments. At least this is the approach used in Haskell, with semi-explicit (explicit in type, implicit in the value) passing of parameters.

If you take a time argument, you have to declare an extra argument, not an extra variable, and in a powerful language, you can abstract its passing around.

If you move the method to a new location where its input is not available, you propagate up the input requirement in the form of argument passing, which conveys the new dependency up the call chain.

Re:Dependency Injection is a Virtue by adamauckland on Monday January 07, 2013 @07:33AM (#5020668)
> If you need to pass the same set of multiple things to multiple functions, you declare a type that represents all these arguments. At least this is the approach used in Haskell, with semi-explicit (explicit in type, implicit in the value) passing of parameters.

So might one call this a Context object?

Re:Dependency Injection is a Virtue by jerf on Monday January 07, 2013 @09:37AM (#5021108)
In Haskell, they call this a Reader. This parallels the Writer, which lets code just 'write' to the provided values but not use them (more useful than it sounds, for instance, logging). But it is basically a context value, yes.
Re:Dependency Injection is a Virtue by Peaker on Tuesday January 08, 2013 @06:06AM (#5025704)
Well, the nice thing about this abstraction in Haskell, is that you can give a name to the notion of receiving a bunch of values (Reader), outputting a bunch of values (Writer), threading state that can be both Read and Written (State), non-determinism (List), etc. You can thus compose all these behaviors you want into a single type constructor and build your programs as composites of this type.