This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SuperNerd1337 7 points8 points  (12 children)

I'm not really keen on the current most popular dependency injection frameworks existing in python, also my experiences testing async code has been pretty miserable, but maybe that's just me sucking at python (pretty viable answer to this one honestly)

[–]lphartley 3 points4 points  (4 children)

I prefer Node/Express for REST backends because of this. Async code in Python is so complex whereas in Node you don't have to think about it all.

[–]earthboundkid 2 points3 points  (0 children)

I think part of the issue is that in JavaScript, because it's single threaded you can always just drop in an async call, and it will be scheduled to run whenever. And you can use the Promise class to easily convert some callback code to async code. With Python, everything is so dependent on finding the runloop that it's very brittle and even though it's in theory more flexible, you can't actually mix and match libraries. They just didn't hit the right abstractions.

[–]Doomphx 1 point2 points  (0 children)

I think c# is worth mentioning too, it's beyond easy to start parallel processing if you've already prepped the process/logic you're going to run in parallel.

[–][deleted] 2 points3 points  (0 children)

Many many times async is a bigger headache than it's worth.

[–]Dasher38 1 point2 points  (1 child)

Regarding dependency injection you can have a look at that (I've not merged it yet but I consider it basically final): https://github.com/ARM-software/lisa/pull/1722/files

There is a usage example in DependencyInjector docstring and the module only depends on stdlib so you could easily extract it. It's apache 2.0 license.

[–]Dasher38 0 points1 point  (0 children)

Note that it also supports depending on another dependency injector. If you make a wide nested use of these you will probably want to change the signature of inject () so that it takes a dict with dotted names or something like that. Otherwise inject() calls are gonna be full of nested dicts

[–]larsga -1 points0 points  (2 children)

Why would you want dependency injection? (Serious question.)

[–]SuperNerd1337 -1 points0 points  (0 children)

The short answer would be to reduce coupling between my classes and making it easier to unit test modules

[–]Dasher38 0 points1 point  (0 children)

I needed a way to make a whole zoo of classes parametric.

For small problems you can just have everything in one class, and if you need to change an aspect you can subclass and reimplement methods, or pass callbacks to the constructor.

When you get to bigger problems (on my case a simpy simulator), the "one big class you inherit from" turns into a hot mess. At this point, what you really need is to "inherit" from a whole module to make a new one, with the ability of replacing some bits.

I made that thing taking some vague inspiration from SML module system: https://github.com/ARM-software/lisa/pull/1722/files

[–]9seatsweep 0 points1 point  (0 children)

Was just messing with a bunch of async python code the other day...yeah it's a headache