Live data from Hacker News

Dependency Injection is dangerous for your career

stackoverflow.com

21–30 of 35 posts

Re: Dependency Injection is dangerous for your career

#22
How can you tell how closely coupled a codebase is when you're in the interview process and not yet an employee?

This is the real challenge. I don't think many companies, outside of perhaps small startups, will let you view their code - at your own perusal so you know they aren't just showing off the good stuff - to candidates.

Re: Dependency Injection is dangerous for your career

#23
post #9
post #8

Earlier quoted context omitted.

DI is generally used to solve one of two problems that are pretty much unique to Java: Passing a function If you will pardon my English: What a load of bullshit. I'm sure it can be used for that as well (i.e. in implementing the delegation pattern, due to lack of delegates and first class functions), but saying that is what it all that is good for simply makes you look inexperienced. For any system with a reasonable…

I know you can implement it with out XML, I do DI all day long with functions. I just don't call it DI, I call it passing functions. When people talk about DI they're generally talking about using a DI framework. My point is that the concept is trivial enough to implement in the language itself and doesn't require a framework to help 'manage' it. What problems can be solved with DI that can't be solved by passing a f…

I know you can implement it with out XML, I do DI all day long with functions.

Non-sequitur. Most .Net DI frameworks (as opposed to DI in Java, or DI without a framework) use configuration in code. This is generally much more readable and flexible than config in XML. Only some of them use functions for some things.

Re: Dependency Injection is dangerous for your career

#24
The following is a comment from Frank Atanassow on a LtU discussion about the Curry Howard correspondence:

blah blah blah dependency injection blah blah blah (This is a bit off-topic, but it came to mind, so what the hell.) You are correct in your observations that given most programming languages (even those such as Haskell), it is difficult to see exactly how Curry-Howard is useful. I recently stumbled across someone mentioning something called "dependency injection". I didn't know what it was, so I googled (I guess this is lowercase nowadays!) it and read Martin Fowler's article on it. It is a bit on the long side, and I kept waiting for the punch-line; you know, the point at which the author hits you with the insight which justifies the preceding verbosity and the hi-tech-sounding name ("dependency injection" — I can't help but think of "fuel injection", and gleaming motor engine showcases), but it seemed indefinitely postponed. And in the end, it turned out that "dependency injection" just means "abstraction" specifically by parametrization, by update and by what I think amounts to type abstraction plus update. (Apparently these are called — I kid you not — type 3 IoC, type 2 IoC and type 1 IoC...!) To me this all seemed rather obvious and it got me thinking about why it isn't obvious to the author or his readership. In Haskell, if I am given some type B which I need to produce somehow, and I realize that the B-values I need depend on some other values of type A, the first thing I do is write down "f :: A -> B". Then I write down "f a =", and then I start writing stuff after the equals sign until I have what I need. I do that because I know once I have the type that if there is an inhabitant of the type "A -> B" it can be expressed as "\a -> b" for some b, so the "f a =" part is always part of my solution and I will never have to change that unless I want to. So once I've written that down I feel one step closer to my solution. I know that for three reasons. First, because of my experience as a functional programmer. Second, because it is part of the universal property of exponentials ("factors uniquely"), that is, of function types. And third, because by the Curry-Howard correspondence with natural deduction, I can start any proof of A which depends on B by assuming A, that is, adding it as a hypothesis. So, why is it so obscure in Java? I think part of the reason is that in Java you have update, so there are complications and additional solutions. But part of the reason is also that it largely lacks structural typing, and that makes it hard to see that a class('s interface) is a product of exponentials. (With nominal typing, you tend to think of a class by its name, rather than its structure.) You could also blame the syntax of method signatures, which obscure the relationship with exponentials and implication. But is the syntax the cause or just a symptom? (You know what I think about syntax...) If CH could be readily applied to Java, perhaps Java's designers would have chosen a more suggestive syntax. But even if they had decided to stick anyway with C-style syntax, the idea of using abstraction to handle dependencies would have been more obvious.

More: http://lambda-the-ultimate.org/node/1532

Re: Dependency Injection is dangerous for your career

#25
post #8
post #6

DI is generally used to solve one of three problems that are pretty much unique to Java: Passing a function Decoupling initialization from memory allocation (eg. making constructors work) (This problem is also shared by C# before 3.0 but you can kind of get around it by passing a function that does the initialization, or using an anonymous constructor in 3.0 and up) Avoiding the FactoryFactoryFactory pattern where it…

DI is generally used to solve one of two problems that are pretty much unique to Java: Passing a function If you will pardon my English: What a load of bullshit. I'm sure it can be used for that as well (i.e. in implementing the delegation pattern, due to lack of delegates and first class functions), but saying that is what it all that is good for simply makes you look inexperienced. For any system with a reasonable…

Great point. This presentation showed how easy it can be to implement DI in ruby: http://onestepback.org/articles/depinj/index.html

Dynamic languages don't suffer many of the overheads with using DI. So do those with Mixins (see the Scala's Cake pattern for more on this http://jonasboner.com/2008/10/06/real-world-scala-dependency...)

This blog post says more about it: http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-pro....

Re: Dependency Injection is dangerous for your career

#26
post #10

Earlier quoted context omitted.

I'll admit I've never done Java programming, but (so far as I understand the term) dependency injection is something I use a lot when writing Python code. For example, if I'm writing a method to transfer a file over a particular kind of connection, I'll make the connection object a parameter rather than have the method set up the connection itself. If I'm writing a class, I might make the connection object a paramete…

Am I missing some magic goo that makes Python not require DI, or do I just not understand what Java programmers mean by DI? Sometimes it's easier to assume Python-developers are blind to architectural problems and common solutions to those. Not saying Python isn't used in large, complex problems or that all Python-code is spaghettti-code, but there are a lot of wannabe cool Python-hackers ("ninjas") out there and par…

"Design patterns" has become an ambiguous term.

There are a lot of design patterns for object oriented programming that were created specifically to overcome structural flaws in C++ and Java. These simply don't apply to some languages.

Dependency Injection is not one of these and actually has widespread applicability. Although the name always sounds wrong to me since it makes me think of dependency creep, one of the problems that it is intended to alleviate.

Design patterns have gained an "enterprisey" reputation because much of the time they are represented as if each one is a universal, language agnostic solution. They reek of cargo cult management.

Every language and/or ecosystem will have its own set of effective design patterns that will partially overlap with those of other ecosystems. Some communities care more about making names for the patterns, which could in itself be considered enterprisey.

Interestingly enough, the person that first told me about design patterns was a Python hacker.

Re: Dependency Injection is dangerous for your career

#27
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 with some third-party API you want to prevent the rest of your codebase from knowing too much about the API - in case you ever need to change gateways - and so you wrap it up in an interface/module/etc to abstract away the details of Gateway X.

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

How would you generally manage this type of thing in a Python system? By giving the web/controller code a different payment module that implemented all of the same method signatures?

Re: Dependency Injection is dangerous for your career

#29
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…

"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 language for actually learning about programming. "Using Dependency Injection" is an absurd way of phrasing "pass in varying parameters as parameters to your function instead of using global variables". What should be the normal way of doing business has instead been elevated to Something Special (that Lesser Languages Can't Do because they don't call it Dependency Injection because they would never think of giving Passing Parameters to Functions a special name!) because Java makes something as easy as breathing and in some cases hard to avoid (try programming Haskell or Erlang with too many global variables) a production.

In Java, you use absurd and unnecessary machinery. In every other language, you just do it. It's hard to even explain how you do it because there's hardly any doing in the it. It's a parameter passed in. It hardly seems worth discussion.

Re: Dependency Injection is dangerous for your career

#30
post #29

Earlier quoted context omitted.

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…

"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 branch to be aware of what the different Gateway modules you might call would be - correct?

Post reply on HN