Live data from Hacker News

Dependency Injection is dangerous for your career

stackoverflow.com

31–35 of 35 posts

Re: Dependency Injection is dangerous for your career

#31
post #3

True. But what's even worse for your career is when you learn programming languages that don't need DI frameworks because that kind of clean separation is baked in (like Python) but then most jobs out there are Java :-(

I am curious about how this type of "clean separation" is generally handled in Python. I mostly have experience with Java, and I have some light Python experience but I've never worked in a large Python codebase. Would you mind telling me how you would handle this in an example? Let's say you were building a web app which had to communicate with some sort of payment gateway API. Naturally since you are communicating…

you want to prevent the rest of your codebase from knowing too much about the API - in case you ever need to change gateways

Maybe I'm naive, but I wouldn't usually bother:

1) Maybe I will never change gateways, then there was no point in writing a wrapper.

2) If I do change gateways, I can just write a wrapper that uses the old gateway's API as the interface for the new one.

If the new gateway is sufficiently different than the old one that it can't be mapped to the old API, then whatever wrapper I wrote back in the beginning before I needed it wouldn't have been sufficient anyway.

Your strategy sounds like YAGNI to me. I only write separate interfaces when I actually have different components that need to be swappable.

But maybe that's just because I'm using Ruby and I can be lazy like that?

Re: Dependency Injection is dangerous for your career

#32
post #29

Earlier quoted context omitted.

"If it ever came time to switch payment gateway backends, in a Java application using DI you would just need to switch which implementation of your interface that the rest of your code is wired up with (either in XML, or if you are wiring up collaborators explicitly in your code, etc)." You simply pass in the desired payment processor as a parameter. End of story. This is part of the reason Java is such a terrible la…

For the sake of this example, let's say that the different gateways have vastly different APIs, messaging mechanisms, etc. So in the code that you are passing a parameter to, you'd have to have some sort of branch based on the parameter value to choose to call Gateway A versus Gateway B - correct? Which requires you, when switching gateways, to change the value of the parameter passed along with possibly updating the…

This is basic object orientation: You pass in an object that corresponds to the desired interface. "Facade pattern" if you need something to Google, but this is really basic language-agnostic OO stuff.

Another reason to dislike the Java cruft; it successfully hides the simple things going on behind immense machinery and complicated terminology.

Re: Dependency Injection is dangerous for your career

#33
post #32

Earlier quoted context omitted.

For the sake of this example, let's say that the different gateways have vastly different APIs, messaging mechanisms, etc. So in the code that you are passing a parameter to, you'd have to have some sort of branch based on the parameter value to choose to call Gateway A versus Gateway B - correct? Which requires you, when switching gateways, to change the value of the parameter passed along with possibly updating the…

This is basic object orientation: You pass in an object that corresponds to the desired interface. "Facade pattern" if you need something to Google, but this is really basic language-agnostic OO stuff. Another reason to dislike the Java cruft; it successfully hides the simple things going on behind immense machinery and complicated terminology.

So this is what confuses me about claims that in Python you don't need all this extra cruft, because the language makes these things possible:

if you are using the Facade pattern in Python for this example, you'd be using the same pattern in Java.

So then, what exactly is different here?

Re: Dependency Injection is dangerous for your career

#34
post #32

Earlier quoted context omitted.

This is basic object orientation: You pass in an object that corresponds to the desired interface. "Facade pattern" if you need something to Google, but this is really basic language-agnostic OO stuff. Another reason to dislike the Java cruft; it successfully hides the simple things going on behind immense machinery and complicated terminology.

So this is what confuses me about claims that in Python you don't need all this extra cruft, because the language makes these things possible: if you are using the Facade pattern in Python for this example, you'd be using the same pattern in Java. So then, what exactly is different here?

[deleted]

Re: Dependency Injection is dangerous for your career

#35
post #32

Earlier quoted context omitted.

This is basic object orientation: You pass in an object that corresponds to the desired interface. "Facade pattern" if you need something to Google, but this is really basic language-agnostic OO stuff. Another reason to dislike the Java cruft; it successfully hides the simple things going on behind immense machinery and complicated terminology.

So this is what confuses me about claims that in Python you don't need all this extra cruft, because the language makes these things possible: if you are using the Facade pattern in Python for this example, you'd be using the same pattern in Java. So then, what exactly is different here?

Nothing! Dependency injection is just programming. You don't need a "framework" for it, even in Java.

Java is crufty in other ways that may make various objects more painful to use than in Python; where you need a zoo of classes in Java you often don't in Python. But this isn't one of those places.

The term does nothing but create confusion for no good reason.

Post reply on HN