General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
TheEvertw
ArjanCodes
comments
Comments by "TheEvertw" (@TheEvertw) on "Dependency Injection Explained in 7 Minutes" video.
"Dependency injection", as explained here, is probably the most simple OO design pattern. In OO, it is called the Strategy Pattern. You hide the details of an algorithm behind an (abstract) interface. The user of the strategy only knows the abstract interface, each implementation of the Strategy interface knows only the details it needs. I don't understand why people wanted to change the name. The name "Strategy Pattern" has been in wide-spread use for 30 years. I guess people like re-inventing the wheel. That is no critique on Arjan, he didn't coin "dependency injection". I thank him for this video, I never understood what people meant with DI. I thought it was some complex trick like the "Curiously Recurring Template" pattern. Which is similar to DI but achieves lightning fast execution & minimal memory footprint, at the cost of long compile times.
7
Seconded. I spotted that as well, you beat me to it. Besides using the factory argument, Python has the Optional typing hint, which expects a None default value.
4
I prefer SMTP as my email sender. Works every time, regardless of how a customer has configured his email server.
1
@dynamicgrad3820 If you pass an empty list as default argument in a function, that default empty list is created once, and then reused every time that function is called. Which means that most likely, after that first function call, that list no longer is empty. And if the list passed to the function is stored somewhere in your code, there are multiple references to that list spread around your data structure waiting to cause nasty and hard-to-debug side-effects. Your Python IDE will warn about this. A better solution is to use an `typing.Optional[List[xxx]]` argument, with a `None` as default argument. `None` is immutable, so it can be safely reused and shared between multiple calls to the function.
1
@dynamicgrad3820 He used a construct that is a common source of nasty bugs in Python: he defined a function with a default argument that is potentially mutable. In Python, there is only one instance of that default argument. When the function is called, the exact same default argument instance is used, which means that it contains the results of whatever the previous function call did to it, and not the pristine clean object you would expect.
1
@dane2565 There are zero guarantees that MailChimp does not store internal state that can not be copied between sessions, now or in the future. So even in this case, it is a definite NO-NO.
1