top | item 43504247

(no title)

ryan-duve | 11 months ago

> And don't even get me started with dependency injection in Python.

Could I get you started? Or could you point me to a place to get myself started? I primarily code in Python and I've found dependency injection, by which I mean giving a function all the inputs it needs to calculate via parameters, is a principle worth designing projects around.

discuss

order

d0mine|11 months ago

Here’s 1% that gives 50% of result. Replace:

    class C:
        def __init__(self):
            self.foo = ConcreteFoo()

with:

   class C:
        def __init__(self, foo: SupportsFoo):
            self.foo = foo

where SupportsFoo is a Protocol. That’s it.