Dustin Getz on 24 Jul 2012 16:09:20 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: followup to PhillyETE: dependency injection without the gymnastics (tony morris on monads)


* "don't see the value-add of pass-by-argument" -> "monadic approach"

On Tue, Jul 24, 2012 at 7:07 PM, Dustin Getz <dustin.getz@gmail.com> wrote:
At PhillyETE, Tony Morris gave a talk "dependency injection without the gymnastics"[1]. (To establish a common language: "dependency injection" is when we structure our functions to take dependencies by argument, instead of hardcoding them, so we can swap implementations e.g. to mock them.)

Tony's thesis is that "injecting dependencies by argument is cumbersome" and "traditional enterprise dependency injection solutions are shitty" (this is questionable to me?) and he goes on to provide monadic Scala code to solve this problem. I've reimplemented it in python to better understand, and I question his assertion, and don't really see the value-add of pass-by-arguments because deeper in the callstack when we get to business logic, we have to pass dependencies by argument anyway.

to help understand what he's talking about, here is a 30 line python program that demonstrates using reader-monad to inject dependencies per Tony's talk. (way easier to comprehend than the wall of code in the slides): https://gist.github.com/3172127#gistcomment-379014

what approaches to DI have you guys seen in the wild? any thoughts as to why Tony asserts that a monadic solution is superior to traditional solutions? i'm really not seeing the value-add here, but he's a smart guy and quite assertive about the superiority of a monadic approach.

[1] http://dl.dropbox.com/u/7810909/docs/di-without-the-gymnastics/di-without-the-gymnastics/chunk-html/index.html