Post Ar2vyavyVRnDrd9sBs by yvan@toot.ale.gd
 (DIR) More posts by yvan@toot.ale.gd
 (DIR) Post #AqzF2D9fylFplnAIhk by stfn@fosstodon.org
       2025-02-10T20:37:52Z
       
       0 likes, 1 repeats
       
       New blog post!This time it's my first post about slightly advanced programming in Python. I talk about using the dependency injection design pattern to separate business logic from I/O calls to have cleaner code and simpler tests.Well, actually the topic is more generic and can be applied to any programming language, but here I use Python as an example.Anyway, here it is!https://stfn.pl/blog/62-python-dependency-injection/#python #programming #softwaredevelopment #pytest
       
 (DIR) Post #Ar0ViQMd3GWDK8Kmq8 by borutzki@mastodon.social
       2025-02-11T11:19:27Z
       
       0 likes, 1 repeats
       
       @stfn Neat thing is that it may make it possible to completely avoid using mocks in unit tests.And other thing, if you use a bit of abstraction you can vary connection types - I did something like this to make it possible to perform the same operations with serial and SSH connections depending on whatever is needed ;)
       
 (DIR) Post #Ar0pd9DfMinnmnu4ae by stfn@fosstodon.org
       2025-02-11T15:02:36Z
       
       0 likes, 0 repeats
       
       @borutzki Yep, exactly this, I think I even mention that second thing at the end of my post
       
 (DIR) Post #Ar2vyavyVRnDrd9sBs by yvan@toot.ale.gd
       2025-02-12T15:23:04Z
       
       0 likes, 0 repeats
       
       @stfn a neat explanation I think.I've seen the term "Dependency Injection" loads since coming back to looking at modern (as in more modern than 10 years ago) programming and frameworks. As a concept I have grasp on it, but the terminology itself was new to me - your post boils down the point nicely against the Python example in ways that are a bit buried in, say, the Wikipedia article.I'm curious as to the etymology of "Dependency Injection" as a design pattern. It was clearly a term in use when I was working as a software engineer, but I don't recall it. I notice the Wikipedia Page was first created in 2005, and cites Java/Spring and RoR as examples. Given I was a C/C++ systems/networking coder I guess it's not surprising if the concept was mainly in web framework circles.I'm familiar with the idea of using "interfaces" in this and similar ways going way back, I guess without knowing this term I'd have just described it as a property and key point of "abstraction".
       
 (DIR) Post #Ar2xq5ZDRbWqAkaJPc by yvan@toot.ale.gd
       2025-02-12T15:34:16Z
       
       0 likes, 0 repeats
       
       @stfn I find this interesting: https://books.google.com/ngrams/graph?content=Dependency+injection%2CInversion+of+Control&year_start=1800&year_end=2022&corpus=en&smoothing=3I actually recall the term Inversion of Control (though I wouldn't have without having seen it on Wikipedia!) and this would follow given it's usage peak is more around my Uni and subsequent dev career times. [Edit: to note there is a difference between the original usage of this and how it was used in ways that link to DI.]Anyway, thanks, I found the post useful in my current quest to get up to date with the world. 😅 (Hm, is there any non-Google equivalent to their n-gram viewer...)
       
 (DIR) Post #Ar2xq6evNrgnYkGNwu by stfn@fosstodon.org
       2025-02-12T15:44:01Z
       
       0 likes, 0 repeats
       
       @yvan Thanks! and thanks for sharing, you are raise an interesting point about the naming. I've heard both "dependency injection" and "inversion of control", and for me the first one is more common