Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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



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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: