Hacker News new | ask | show | jobs
by ditt84576 4564 days ago
I've seen Spring projects with more xml than actual source code. When you ask why it's being used you hear 'to do dependency injection'. There was an excellent talk recently with a quote along the lines of: what Java programmers call dependency injections is just called passing variables in other languages.
3 comments

Seriously. Using even a relatively crummy PHP framework like CodeIgniter feels like heaven compared to the burdensomeness and complexity of spring/hibernate. Need a new controller, a few new models, and a couple new views? You can get that done in a snap in any reasonable MVC framework but with spring you'll be pulling teeth and it'll feel like a good day's work if you can get the skeleton working.
It really depends on the size of the project. Having used CodeIgniter for a few projects, and Spring extensively for 2-3 years, there were projects where I really appreciated CodeIgniter - basically self-contained CRUD apps with a bit of originality layered on top - but other times where the CI approach would have led to a lot of pain, as in multi-layered applications that relied on legacy integrations.

I don't think it's unreasonable to prefer the simpler projects that the smaller frameworks are a good fit for, of course! Sometimes though the project is big enough that something like Spring is going to save you time and headaches in the medium and long run.

Are you using an especially old version of Spring? I work with Spring MVC on a pretty regular basis and I've never had that much trouble with defining a new controller/model/view.

Controller: Add an @Controller annotation and some @RequestMappings and you're done.

Model: Usually these have no Spring dependency at all, though there are annotations you could put on some of the fields for various tasks if you'd like.

View: Also mostly unrelated to Spring. Write a Thymeleaf template or JSP and return the name of it from the appropriate controller method.

It's quite fashionable these days to hate xml configuration, and abandoning xml seems to be the way even Spring development is going (Java Config, spring-boot, etc). However, I've found some good points with it too. When you have less java code and more xml, it is often faster to come up to speed on a new spring project because the xml more quickly describes how the project is integrated - maintenance and tweaks can often be more straightforward. In contrast, Java code and annotations often feel friendlier for the actual process of developing.

I do think I prefer the java way more, because it's a bit easier to debug. But once I have some solid java code, I can be tempted to lift out 30 lines of code if it has an analogous 5 lines of xml config.

Usually 10 lines of java, which is already quite verbose turns into 30 lines of xml.
Your last statement about the quote is half true half "but other prog. lang. devs rarely write unit tests and even if they do they write integration tests that requires DB"

I found Spring libraries to be useful. I don't doubt there are people who abused it as well.