r/programming • • Nov 27 '15

Why I hate Spring

http://samatkinson.com/why-i-hate-spring/
73 Upvotes

140 comments sorted by

26

u/[deleted] Nov 27 '15

They blame Spring, Java EE, Hibernate, etc. The only thing they don't blame is themselves.

3

u/stormcrowsx Nov 28 '15

They blame themselves for using it

2

u/djhworld Nov 28 '15

Hindsight is a wonderful thing though

19

u/estarra Nov 27 '15

It wasn't that long ago that people said that Java EE was a horror and Spring was the only sane way to develop applications.

What's the technology loved today that will be loathed in a few years?

13

u/[deleted] Nov 27 '15

It wasn't that long ago that people said that Java EE was a horror

It's not that long ago that Java EE was a horror. It's a lot more pleasant to work with now than it used to be.

2

u/dpash Nov 29 '15

And it was competing with spring that dragged it out of hell.

1

u/[deleted] Nov 29 '15

Absolutely -- not just Spring, mind, but Spring was certainly the main impact.

35

u/tweakerbee Nov 27 '15

I'm betting on Node.js

13

u/TheGuyWithFace Nov 27 '15

I'm wayy ahead of you.

4

u/AcidShAwk Nov 28 '15

I see pure hate on Node.js. Fortunately Its been an awesome addition for our platform. Like any tool, figure out how it can be of value first.

2

u/Patman128 Nov 28 '15

Yup, everyone hates Node. Even I did, until I started using it more and realized it's actually pretty damn nice. But it will take a few years for /r/programming to accept it. I can understand the conservative mindset, especially around JavaScript stuff since the churn used to be pretty fast.

0

u/[deleted] Nov 27 '15

[deleted]

20

u/_INTER_ Nov 27 '15

I already loath Node.js now.

3

u/probablyunsound Nov 28 '15

Why?

2

u/_INTER_ Nov 28 '15

Mainly because of JavaScript. Also the whole "feel" and community behind it bothers me.

4

u/johnwaterwood Nov 27 '15

What's the technology loved today that will be loathed in a few years

Hope it will not be loathed in a couple of years, but the technology loved today is Java EE ;)

1

u/OneWingedShark Nov 29 '15

What's the technology loved today that will be loathed in a few years?

Go and/or Rust.

-1

u/[deleted] Nov 28 '15

We decided there wasn't one. My new job uses Spring MVC for APIs because it's something we know. Everything Servlet is terrible and no one has developed a mainline Netty framework that's simple and lightweight. Anyone that's doing anything sane is probably in Node, which is amazing, except that it is written in javascript (type safety is really necessary for reliable code).

If you're talking about a DI framework, the best answer is none. If your DI framework scales, it's because your team is professional and diligent and has nothing to do with the DI framework. Creating objects using the most appropriate pattern (Singleton, Factory, etc) is nearly equivalent to Spring's Java Config and removes the magic of annotations that fail miserably. Plus even with all of Spring's large feature set, there are still things that it can't handle. Removing the framework provides a huge level of freedom and let's you write pure Java, which is always simpler to debug and teach than any framework.

-4

u/ns0 Nov 28 '15

react. angular.

37

u/jordimaister Nov 27 '15

Nice post. Agree with almost all of it.

I am waiting for you next post:

"What to use instead of Spring"

33

u/tomservo291 Nov 27 '15

That's easy, just write Java and create your own graph of objects out from your main method. I went through the same phases as the OP and have migrated to never use any magic. I use lots of third party libs, but only that live 100% in their own sandbox and don't leak out things like spring dependencies, etc.

9

u/redox000 Nov 27 '15

Initializing everything in main is not feasible in large apps with lots of IoC/DI. How do you initialize apps without ending up in "new" hell like this?

var svc = new ShippingService(new ProductLocator(), new PricingService(), new InventoryService(), new TrackingRepository(new ConfigProvider()), new Logger(new EmailLogger(new ConfigProvider())));

16

u/sstewartgallus Nov 28 '15

What's wrong with the following?

 public static void main(final String[] strs)
 {
 	final ProductLocator productLocator = new ProductLocator();
 	final PricingService pricingService = new PricingService();
 	final InventoryService inventoryService = new InventoryService();
 	final TrackingRepository trackingReposiotry = new TrackingRepository(new ConfigProvider());
 
 	final Logger logger = new Logger(new EmailLogger(new ConfigProvider()));
 
 	final ShippingService svc = new ShippingService(productLocator, pricingService, inventoryService, trackingRepository, logger);
 
 	svc.go();
 }

Maybe named parameters, record types or builder objects might be useful here but I don't see a need for huge and complicated frameworks.

2

u/silly-gamer Nov 28 '15

The only thing one can argue is that it is not seemingly open to aspects or things where you require cross cutting concerns.

Otherwise I'd generally agree. This is on the opinion of only use a framework when you really have a good reason to use one :)

7

u/redox000 Nov 28 '15

This architecture will not scale well. What happens when you have 4 or 5 levels of nesting in your dependencies? If you try to build the parent object in main, that constructor will be enormous. Another problem is that it's very easy to unnecessarily new up instances instead of sharing them. You made that mistake in your example, you have separate instances of ConfigProvider being passed to TrackingRepository and Logger.

10

u/case-o-nuts Nov 28 '15

This architecture will not scale well. What happens when you have 4 or 5 levels of nesting in your dependencies?

I refactor the code and simplify things.

8

u/valenterry Nov 28 '15

You also have those nesting levels when using spring. You just don't see them because they are flattened. Somewhere someone has to tell, who is gonna use who. You can move that point to other files but it remains.

5

u/lyinsteve Nov 28 '15

Along with a ton of extra overhead.

12

u/[deleted] Nov 28 '15

Simply have methods for the reusable objects. Create on first call, return same instance on second call. A basic factory, one line of code per method.

2

u/Chii Nov 30 '15

And slowly, over time, you've written a shitty IoC. There's lighter weight IoC frameworks like guice, which is what I'd use for any java projects with more a few levels of deps.

2

u/[deleted] Nov 30 '15

Slowly, over time? No, it's done. It's just simple methods returning objects. There is nothing more to do here, job is done.

If you think this is "shitty IoC" be specific what you don't like about it, but by the way you use "IoC" in a sentence, I'm suspicious if you know what it is. Inversion of control is a concept, a pattern, not a framework. It doesn't require boilerplate, it's a specific separation of responsibilities between caller and callee.

0

u/Chii Nov 30 '15

When you hand roll code to create objects, it works at first. When you have a pretty simple project, with may be 1-2 level deep dependency tree. What happens when you now have a 3-4, or higher level deep dependency tree? You have to start passing the factories around, or make them static methods on classes (which means you can't easily mock them in a unit test).

There's nothing wrong with using an IoC framework. Spring is an OK one, guice a little bit lighter weight (but less features - e.g., it doesn't have a way to do component-scanning). A hand-rolled framework (which is what you described - consisting of manually writing factories, then using them where it's needed), might seem like a good idea when it's early on in a project - especially when you don't want the overhead of a framework. But if a project has any depth or scope, especially if it's a project that might have plugins or external code contributions, such a hand-rolled framework always become a liability.

3

u/[deleted] Nov 30 '15 edited Nov 30 '15

You keep saying "hand rolled framework" while the thing being discussed is a basic factory, I have to wonder if you know what a "framework" is as well. The scenario you describe simply doesn't exist. I "hand roll" my wiring precisely because my projects are big and modular, and I need the control inverted to the application boostrap and not scattered around in vague XML files and annotations.

I write this code because I realize it's the most important aspect of my application - the logic that hooks the parts into a whole exactly as I need and not by random happenstance and type name matching.

When you have a project that largely consists of reusable modules, it's not a smart idea to embed project-specific configuration in annotations on supposedly project-neutral components, don't you think?

When you use annotations and autowiring in Spring, do you realize the very point you seem to stress about, namely inversion of control, gets the knife? Annotations represent inversion... of inversion of control. Information that should be specified outside the object is instead embedded back on it, same as would be the case if you directly instantiated dependencies inside it, or fetched from a global service locator.

Spring doesn't assist IoC, in fact it provides tools which quickly and swiftly destroy it.

Ever needed empty "tag" classes and interfaces? Or qualifier annotations? Tell me, how does this fit into the whole "the object is not aware of its environment" concept of IoC. With qualifiers, it seems that the object is painfully aware not just of the existence of a container, but also how is that container configured exactly with qualifiers. This is no IoC.

→ More replies (0)

15

u/gavinaking Nov 28 '15

I must admit that "new hell" is not a problem I have ever once experienced in > 15 years of Java development.

I mean, I guess I can believe that perhaps it occurs in certain problem domains, I just find it pretty difficult to believe that it's really all that common.

1

u/tomservo291 Dec 05 '15

By not writing code that's designed for IoC/DI only?

I've written big apps post-IoC/DI. Couldn't be happier... Just follows different patterns, that's all. Lot's POJO's. "Real" unit tests (spring unit testing... gag)

1

u/[deleted] Nov 27 '15

Use factories and builders. Let main decide which implementations to use for them. Then you can feed main config files to change behavior.

14

u/redox000 Nov 28 '15

You're just rolling your own container implementation. Your config file to change behavior is no different than Spring's config file, except you have to do all the dirty work of creating and maintaining a container. Why not use an existing library where other people who are smarter than either of us have put the hard work into figuring out the best way to implement a container? If you don't like Spring, there are plenty of other options.

9

u/[deleted] Nov 28 '15

Creating my own objects is basic Java which is necessarily easier to teach, debug, and maintain than any DI framework. As I say elsewhere, any application that has a scalable object management system is due to the professionalism of the engineers, not the framework. Spring has so many variants, poor Spring is much worse than poor basic Java.

1

u/stormcrowsx Nov 28 '15

I really enjoy guice. It gives great error messages when you make mistakes, I had circular dependency and it let me know all the involved classes to cause it.

4

u/brikis98 Nov 28 '15

2

u/juwking Nov 28 '15

I hope you understand that this is about Spring, as a whole, not Spring MVC.

4

u/ErstwhileRockstar Nov 28 '15

"What to use instead of Spring"

Pure current Java EE. The Standard. Implemented and supported by a dozen of (free and commercial) providers.

5

u/[deleted] Nov 27 '15

Very good point. Everyone nowdays is competitive enough to recognize problem, but people need solutions.

3

u/BarneyStinson Nov 27 '15

What problems does Spring solve for you that you cannot solve without it? How do Go/Clojure/C++ programs handle those problems?

5

u/Databean Nov 27 '15

Guice (annotations read at runtime) or Dagger (annotations read at compile-time)?

10

u/sacundim Nov 27 '15 edited Nov 27 '15

The problem here is that over the past 6-7 years, dependency injection frameworks for Java took a very wrong turn. The original model—which the original Spring XML-based BeanFactory embodies—is that you have named "beans" which are described by specifying:

  1. The name of the "bean"

  2. What to call to construct it (the implementation class or factory)

  3. The collaborators needed to construct it. These can be:

  • Primitive values

  • References (by name) to other managed beans

  • Collections thereof

In spite of old Spring's flaws (overly verbose XML configuration, preference for setter-based injection, etc.), the basic model was sound.

But then with the rise of annotations and madness, this model was deprecated in favor of magical/implicit "autowiring" models that suffer from a fundamental flaw. They're all built around variants of this assumption:

  • The type of the injection site determines what dependency to inject into it.

So for example, if you have two injection points whose type is ConnectionPool, the injector will inject both with a RealConnectionPool in a production configuration vs. a TestConnectionPool in a test configuration.

The problem is that this assumption is fundamentally at odds with the concept of code reuse. A good illustration of this is the scenario that Guice docs refer to as the "robot legs" problem:

How do I build two similar but slightly different trees of objects?

This is commonly called the "robot legs" problem: How to create a robot with two Leg objects, the left one injected with a LeftFoot, and the right one with a RightFoot. But only one Leg class that's reused in both contexts.

In other terms:

  1. The Leg class is a generic, reusable class that delegates some unessential details to a dependency that implements a Foot interface;

  2. This Foot interface admits of implementations that behave differently;

  3. Plugging different subtypes of Foot into Leg gives you usefully different behaviors;

  4. You want to exploit this in your program and use Legs with different Foot types in different parts of your program.

The newfangled DI frameworks like Guice and Dagger really don't like it when you try to do this. There are workarounds, but they're that, workarounds. And what's worse, since people tend to follow the path of least resistance when using a tool, these DI frameworks discourage this sort of code reuse!

And what's worse, the bad "injection point type determines dependency type" model has been enshrined as standard by JSR-330.

4

u/bestsrsfaceever Nov 28 '15

Aren't these problems solved by named injections?

5

u/sacundim Nov 28 '15

Let me generalize my point a bit. This is the assumption that modern Java DI makes that I object to:

  • Every injection point determines a unique dependency, relative to some shared context (e.g., injector, module, what have you).

Named injections still make that assumption. I'll copy one of the examples from this page:

public class AuthenticationFilter implements ComponentRequestFilter {

   @Inject @Named("HttpBasic")
   private AuthenticationService basicAuthService;

   @Inject @Named("HttpDigest")
   private AuthenticationService digestAuthService;

   @Inject
   private Response response;

   ...

}

The @Named annotation allows two injection points with the same type to have two different dependencies. But what it doesn't allow is for the same injection point to be supplied with two different dependencies in two different instances of the class. That's what the Leg/Foot example is about; Leg has only one injection point for a Foot, but your application needs two Legs that depend on different types of Foot.

1

u/bestsrsfaceever Nov 28 '15 edited Nov 28 '15

But the implementation of each leg can depend on a different implementation of foot.

Edit:Never mind I followed your link but that seems like an antipattern to me and I don't see how this is impossible in dagger, unfortunately I'm stuck on my phone so I can't read into it more right now

1

u/sacundim Nov 28 '15

Staring at the example I copied in my GP post, now I can't help but wonder whether it should be refactored to something like this:

class AuthenticationFilter implements ComponentRequestFilter {
    // Only one `AuthenticationService` in this class
    @Inject private AuthenticationService authService;

    @Inject private Response response;
    ... 
}

/**
 * An authentication filter chain filters a request by delegating it through
 * a sequence of individual authentication filters in turn.  If one accepts
 * then the whole chain accepts, otherwise the chain rejects.
 */
class AuthenticationFilterChain implements ComponentRequestFilter {
    @Inject private List<? extends AuthenticationFilter> authFilters;
    @Inject private Response response;
    ... 
}

These classes are more generic and easier to reuse. For example, if we need to support a third authentication method, we can now just write a third AuthenticationService, plug it into an AuthenticationFilter instance and stick that into the AuthenticationFilterChain's list of filters.

But now we have a robot legs problem, because we want to construct:

  • An AuthenticationFilterChain that contains...

  • A List of two AuthenticationFilters...

  • One of which contains an AuthenticationService named "HttpBasic"...

  • One of which contains an AuthenticationService named "HttpDigest".

This one example might be refactorable into something that Guice multibindings or similar features can support. But as far as I understand, you'd have to split AuthenticationFilter into multiple classes, each specialized for one type of AuthenticationService.

But now you're letting the DI is dictate the factoring of your code. And that is precisely my problem. The code for an application that's wired up by DI should be factored to suit the application's purpose, not the DI. (And for similar reasons, I object to the concept of putting DI annotations into application classes.)

4

u/gavinaking Nov 28 '15 edited Nov 28 '15

It seems to me that you neither need nor want a DI framework to build a Robot. That seems to be quite a bad usecase for DI.

Dependency injection I guess sorta makes sense when you have a bunch of contextual services that need to be assembled together without wanting to have the final assembly be very dependent on exactly how each service comes into existence or what is the lifecycle of the thing that implements each service.

But most object graphs aren't really like that, and it's better to assemble them in ordinary code. Your Robot is an especially good example of that, I would say.

5

u/sacundim Nov 28 '15

I think your argument begs the question; it takes the new, type-based resolution model as the standard for DI. If I take the old named beans DI model as the standard instead, I can argue that Robot is a perfectly reasonable use case for DI, since that model handles robot legs scenario straightforwardly. The left and right leg are simply different named beans, and you just individually specify what Foot to wire into each.

5

u/gavinaking Nov 28 '15 edited Nov 28 '15

But why? What purpose does dependency injection serve in this case? What problem does it solve?

The pieces of a Robot aren't the kind of "contextual services" for which DI—at least to me—makes sense. They're just ... bits of the Robot, and you can create them with new.

To explain further: my point is that as soon as each instance of Robot has a different sort of Leg, and a different sort of Head, that are specific to the particular instance, then DI has lost its usefulness. You're going to have to somewhere write code that completely describes the Robot and instantiates each of its component parts. You might do that in Java, or you might do it in XML.

I personally would prefer to do that in ordinary Java code using new. I don't see what I gain from having a DI container in the way.

1

u/sacundim Nov 28 '15

But why? What purpose does dependency injection serve in this case? What problem does it solve?

Not having to hardcode the dependencies of objects into their classes themselves. Not having to repetitively write one factory class after another and another. Allowing components' dependencies to be resolved at runtime. Allow components' interconnections to be rewired by changing configuration instead of code. Generic tooling to support the dependency inversion principle.

Yes, all of those are generic pro-DI arguments, and they apply here just as well.

The pieces of a Robot aren't the kind of "contextual services" for which DI—at least to me—makes sense. They're just ... bits of the Robot, and you can create them with new.

Two remarks here:

  1. Perhaps the choice of "robot" as the example is throwing you off? Maybe we can cook up an example where instead of "robot" we use something that you'd call a "contextual service."

  2. I don't buy the assumption that DI should only be for "contextual services" anyway. It's a general tool for wiring up components.

Anyway, my broader argument has another set of consequences that I think you're missing. You're saying that I shouldn't use DI for this sort of scenario. Which I don't nowadays, so we in fact agree on the practical choice for this case.

But then my problem is that when people do choose to use DI, the "one injection point = one unique dependency" assumption may shape the design of the systems that they write away from code reuse. I'll go with the robot metaphor again: the newer frameworks create a path of least resistance that I worry leads people into writing RightLeg and LeftLeg classes that really ought have been just one Leg class composed with different types of Foot.

"Choose composition over inheritance" is a popular guideline... but the newer DI frameworks often will punish you for doing that.

2

u/gavinaking Nov 28 '15

Perhaps the choice of "robot" as the example is throwing you off? Maybe we can cook up an example where instead of "robot" we use something that you'd call a "contextual service."

Well yeah. I mean, if you actually can cook up such an example, one that looks representative of a sufficiently large class of problems, then I guess that's what I'm looking for, and I guess I would be satisfied by that.

I'm really struggling to come up with a case like that in any of my own projects, but of course I'm prepared to accept that it might be something that is domain-dependent.

But then my problem is that when people do choose to use DI, the "one injection point = one unique dependency" assumption may shape the design of the systems that they write away from code reuse.

Well my big problem with DI is that it has this kinda "viral" effect where if you want to inject some container-managed object you have to be a container-managed object yourself. And so people get "nudged" toward a design where almost everything is container-managed, and there's no ordinary objects left except for trivial things like Strings. And I don't think that this leads to necessarily very good use of object orientation.

1

u/sacundim Nov 28 '15

I mean, if you actually can cook up such an example, one that looks representative of a sufficiently large class of problems, then I guess that's what I'm looking for, and I guess I would be satisfied by that.

How about the two code fragments in my two comments in this thread? It might not be perfect just yet, though, but it might be some progress toward that.

1

u/gavinaking Nov 29 '15 edited Nov 29 '15

Well, OK, that example is pretty different to Robot, and perfectly reasonable.

But it's also very easily solved using inheritance:

public abstract class AuthenticationFilter implements ComponentRequestFilter {
    abstract AuthenticationService getAuthService();
    @Inject
    private Response response;
    ...
}

public class BasicAuthenticationFilter extends AuthenticationFilter {
    @Inject @Basic
    private AuthenticationService basicAuthService;
    AuthenticationService getAuthService() { return basicAuthService; }
}

public class DigestAuthenticationFilter extends AuthenticationFilter {
    @Inject @Digest
    private AuthenticationService digestAuthService;
    AuthenticationService getAuthService() { return digestAuthService; }
}

And I would argue that this solution, in pure Java, is much superior to the solution where BasicAuthenticationFilter and DigestAuthenticationFilter are instead defined in XML. If you insist, you could view BasicAuthenticationFilter and DigestAuthenticationFilter as "configuring" their superclass by supplying a concrete value for its templated dependency. The nice thing is that since I've done everything in Java, I will get lot of help from the compiler and IDE when writing/changing this code that I would not get if it were a mix of Java and XML.

Now, sure, there is a bit of unfounded superstition which claims that inheritance is fragile and XML is more "configurable". I don't have any truck with this sort of folklore, and I will always use the tool that is most natural, convenient, and/or elegant for a given task. And I much prefer to remain within the security perimeter of the static type system.

2

u/stormcrowsx Nov 28 '15

I use only constructor injection with guice, no setters and no reflection. Works great, I often test without even bothering with the container since I can inject with plain java code.

2

u/[deleted] Nov 28 '15

At that point, what benefit does Guice provide? Why not stick to base Java to handle DI from a main (or equivalent for application type) rather than using a framework?

1

u/stormcrowsx Nov 28 '15

Handles stuff like singleton and makes it easier to mock large portions of your app for testing.

2

u/[deleted] Nov 29 '15

It is terrible that Java doesn't have a singleton class, which is the real problem there. However using pure Java to create a Singleton pattern (which is not much code) is more maintainable for a project than using a DI framework. Debugging and teachability are much easier without frameworks.

Guice does not make testing easier, I can create an object with mocks just as easily as Mockito can inject them. Plus there's way less reflection.

-3

u/ksion Nov 28 '15

Plugging different subtypes of Foot into Leg gives you usefully different behaviors;

Yet those behaviors are both gathered under the umbrella interface of Leg? That's a blatant violation of the Liskov substitution principle, and it's a good thing that Guice doesn't support shooting yourself in the Foot (har har) like that.

However, if what you meant by "generic Leg class" is Leg<? extends Foot>, then that's all fine. You can have that, along with possibly different injections for Leg<LeftFoot> and Leg<RightFoot> in your Robot.

4

u/sacundim Nov 28 '15 edited Nov 29 '15

That's a blatant violation of the Liskov substitution principle [...]

No it's not. Look at it this way. For your argument to follow here, one of these must be true:

  1. The subtypes of Foot violate the LSP.

  2. Composition of LSP-compliant classes can nevertheless violate the LSP.

If the first is true, then what Leg does is just irrelevant. The second is just wrong.

Or perhaps more concretely: substitute Leg with BufferedReader, Foot with InputStream, RightFoot and LeftFoot with FileInputStream and ByteArrayInputStream. Now:

  • The composition of BufferedReader with ByteArrayInputStream reads a stream of bytes from a byte[] and converts it to a stream of characters.

  • The composition of BufferedReader with FileInputStream reads a stream of bytes from a File and converts it to a stream of characters.

BufferedReader's behavior is still the same—it converts a byte stream to a character stream. So is InputStream's—it produces a stream of bytes. Precisely where the bytes come from is a function of what InputStream an individual BufferedReader is composed with.

6

u/Yojihito Nov 27 '15

C# ( ͡° ͜ʖ ͡°)

1

u/[deleted] Nov 28 '15

A stream processing framework perhaps.

1

u/[deleted] Nov 29 '15 edited Nov 29 '15

Nice post. Agree with almost all of it. I am waiting for you next post: "What to use instead of Spring"

Java. The author doesn't have a "what to use" alternative, because he's a better programmer now.

As he says in the article Spring is often a crutch for beginners. Once you know what you're doing, using a framework no longer seems like a benefit, because you suddenly possess the magical capability to write code which is faster, cleaner, and shorter than your framework-using code, but... without the framework.

We'll always use vendor-supplied libraries, of course. We still sit on the shoulders of giants. But "generic app frameworks" are most often a malignant formation that is bound to get hated on sooner or later as its users mature. While there's no right way to do it, frameworks look cool and exciting in demos, and learning how to properly architect your application seems boring. So beginners will keep falling in the framework trap, and the world will keep spinning.

-5

u/kyllo Nov 28 '15

Clojure, Scala, Kotlin, Ceylon, Frege, JRuby, Jython... literally any JVM language that supports first-class functions. Dependency Injection is a tortured workaround that's only necessary in Java.

6

u/llaammaaa Nov 28 '15

What are your thoughts on https://github.com/stuartsierra/component is seems that some people who know clojure better than me think that some kind of dependency injection is needed for large clojure programs.

1

u/kyllo Nov 29 '15

I haven't used component but I can see how that is useful--it gives you a central namespace where you can plug in and stop/start/reload each of your module dependencies. But I really don't think it's necessary in the same way that DI is necessary in Java. In Java, DI is required to keep your modules modular and enable basic unit testing.

0

u/bestsrsfaceever Nov 28 '15

I think dagger is the new di hotness, can't speak for the other parts of spring

0

u/[deleted] Nov 27 '15

[deleted]

11

u/johnwaterwood Nov 27 '15

Java EE 😉

6

u/[deleted] Nov 28 '15

If you want a fast REST api over a CRUD database then Dropwizard is probably the best choice. I love Dropwizard, I've deployed it into production at two companies and I have no regrets. I've also deployed a lot of Spring Boot and they're in very different categories.

You can get a ton of well designed features out of the box with Spring that would require a ton of work to implement anywhere else. In a few hours you can create a REST api with HATEOAS, RBAC, Swagger, Asynchronous writes, simple scheduled jobs, a (Eureka|Consul) service discovery client, Zipkin traceability, async error handling, SSO and centralized configuration management.

It's a shame how much historical garbage there is in the Spring ecosystem and how terrible the docs are. It's not really hard to do Spring correctly, but it's probably kind of rare. See: https://jhipster.github.io afaik most new Spring projects are in the dark ages with setter injection inside XML and config management with PPC.

0

u/[deleted] Nov 28 '15

[deleted]

4

u/[deleted] Nov 28 '15

Dropwizard's pretty awesome. It's simple to configure. It's fast to start. You can write SQL by hand in a sane way with JDBI.

Dropwizard + Guice + Shiro + JDBI + Lombok https://github.com/airbnb/airpal

On the other hand, Spring Boot has better testing facilities and a much richer ecosystem. Spring Boot + Hibernate https://github.com/jhipster/jhipster-sample-app

There's more wheel reinvention with Dropwizard compared to Spring, but it's easier to debug and learn.

6

u/[deleted] Nov 28 '15

I'll take Spring any day of the week over the likes of Wicket.

Yes XML config sucks which is why most people use annotations or Java config.

6

u/silly-gamer Nov 28 '15

My take home lesson. The moment you hit this 'realization':

"I just thought it must need more documentation or that the people using it were being stupid"

In a workplace where things are done as a team, then there is something seriously wrong.

Also, the TDD argument is really weak. It is possible to TDD your code with Spring (there's a whole section on testing in their reference documentation).

I am not for or against spring. I just get irritated when you use something that is not fit for the job:

"I was building was a custom RPC layer based over JMS, protobufs and Kaazing to be used across our department and further around the bank." - Sounds like buzzwords to put onto a CV to impress the next employer than actually solving a problem.

4

u/geoffpado Nov 28 '15

For me, it's the seasonal allergies.

27

u/davodrums Nov 27 '15

Hating "Spring" is like hating pizza. There's so many different types of pizza out there, I find it hard to believe you hate ALL pizza. Most of the author's comments here seem like they are complaints from 2005. XML configuration? I haven't used spring XML configuration in at least 3 years. Magic? Only if you don't understand dependency injection BEFORE you apply a spring framework. Breaking up modules? Spring grew so big, it was a requirement to break it up. It's net benefit. Lastly, Spring boot is one of the best things I've found for having onboarded a new microservice arch, and have things "just work" out of the box while we develop new features. Spring does take some understanding, but if you understand what it's doing, its a HUGE benefit and a great tool.

12

u/[deleted] Nov 27 '15

I'd have to agree. I wasn't all too fond of Spring long ago but recently when I tried setting up an app with Spring boot and Gradle, I loved it.

7

u/CyclonusRIP Nov 27 '15

Ya. I really get tired of everyone who calls anything they don't understand magic. If you aren't comfortable with annotations because you don't know how they work then learn how they work. If you learn the reflection package in java then you know how Spring annotations work. The reflection package is a really powerful tool. It's honestly ridiculous that so many people seem to think they are java experts and resort to calling code that makes use of reflection magic.

2

u/tomservo291 Nov 27 '15

Annotations aren't magic, the problem is if it's not checked at compile time, your less competent co-workers will never truly understand it. Once your typical 9-5 coder can't fully grasp it without being reminded every other day how it really works, then as far as I'm concerned, it's magic.

If you keep it stupid simple, then I don't have to stop and explain the perceived magic to them in a never-ending cycle

-1

u/[deleted] Nov 28 '15

Learning how annotations work when they don't provide any value is not reasonable. As they are based on reflection they invalidate Java's compile time checking, one of the most important features for using Java. When building applications, we should be using the strengths of our tools or choosing different tools. If you don't want compile time type safety, I suggest any of the dynamic languages, which are very viable.

3

u/zarandysofia Nov 27 '15

Hate 99% of pizzas because I hate cheese

0

u/rydan Nov 28 '15

I use Spring at work. About once every 3 or 4 months or a lot when initially starting a project I need to to create a node in an xml document that has a package name. Granted this isn't pure Spring. We have an entire team that has developed a framework around it and we are technically using that framework but the underlying technology is definitely Spring.

-6

u/tomservo291 Nov 27 '15

You deployed spring boot to a prod env? Hope you got all those automatically-turned-on services thoroughly pen tested...

6

u/ByzantineFailure Nov 28 '15

Most of this is pretty exaggerated, if you are taking 30 to 60 seconds to spin up a container, it's something you did wrong, not spring.

If you don't use a DI container, you'll end up implementing one yourself, poorly.

The magic criticism is a bit silly, I can't tell if he's talking about the annotations (which aren't good) or the XML. The XML is certainly not magic, and it's quite easy to see what is going on.

Spring is complex if you make it complex, but it's not nearly that bad. We use spring pretty extensively, and it's rarely something we have to mess with.

2

u/[deleted] Nov 29 '15 edited Nov 29 '15

If you don't use a DI container, you'll end up implementing one yourself, poorly.

"Implementing a container" is a POJO class with a few one-line methods that return objects.

It's not hard, it's not a lot of work, and it's nearly impossible to do it "poorly".

2

u/[deleted] Nov 28 '15

When referring to magic, he's meaning the annotations. In my experiences with projects using Spring DI there are 3 classes of DI: XML based, Java based, and Annotation based. He and many others have done an excellent job breaking down why XML config is terrible. You seem to agree that Annotation based configuration is horrible to debug plus removes Inversion of Control for anything interesting. And so my question to you is: If you use a purely Java based Spring configuration, what is Spring actually providing you?

1

u/dccorona Nov 29 '15

If you use a purely Java based Spring configuration, what is Spring actually providing you?

It unifies how you interface with dependencies. You're not constantly reaching out into the place where such-and-such component comes from. Maybe component A comes from a factory and component B is directly instantiated...why should some person who just needs these components have to know that in order to get their stuff working? They just know these are the dependencies they need, and that we're using Spring on this project so they can get them from the Spring context.

It also saves you a lot of management overhead. Enforcing that a component is a singleton. Booting up background processes when the application starts. Running them on a scheduled basis. Shutting them down when the application shuts down. All of that is avoidable boilerplate, which something like Spring, whether it's XML or Java, provides you.

I think a better question is...how is this:

<bean name="myThing" class="com.project.folder.MyThing">
     <constructor-arg ref="dependencyA" />
     <constructor-arg ref="dependencyB" />
</bean>

buying you anything more than this?:

@Bean(name = "myThing")
public void makeMyThing(DependencyA dependencyA, DependencyB dependencyB) {
    return new MyThing(dependencyA, dependencyB);
}

The way I see it, the latter offers everything the former does, and more (primarily, the exact code used to create your dependency in production is entirely accessible and testable from any code that wants to call it, even without Spring at all).

1

u/[deleted] Nov 29 '15

I'm advocating dumping Spring or any DI framework. Why would you ask me to defend XML Spring config?

1

u/dccorona Nov 29 '15

The way you phrased the question implied that you were saying Spring XML gives you something that Spring Java does not. You said:

If you use a purely Java based Spring configuration, what is Spring actually providing you?

Which means that you think that Spring is at least providing you something it you aren't using pure Java config. Or at least it comes off that way.

2

u/[deleted] Nov 30 '15

Not in the context of the whole post. I explicitly state that others have provided excellent arguments against XML configuration and that you stated Annotation configuration is bad. So then I asked you to defend Java configuration, it is easily and quickly converted into a non-framework DI pattern which is necessarily better than applying a framework to Java.

1

u/dccorona Nov 30 '15

I'm not the one who said annotation configuration is bad, I'm a different poster. I don't agree with that statement at all. Although, when I look at how my team uses it, we aren't really using it for dependency injection at all. But there's a lot that Spring offers that isn't dependency injection, primarily for application lifecycle management. So yea, if you're looking at Spring only as DI framework, then perhaps I do agree.

1

u/[deleted] Nov 30 '15

The only spring tools I've used are the DI framework and MVC, both of which I loved when I found them (vast improvements over Java EE at the time), but now I couldn't think of anyway they help.

What are the parts of Spring you primarily use? I think of Application Lifecycle Management as a process (builds and deploys), not a coding framework.

1

u/dccorona Nov 30 '15

The most useful thing I've used it for is for processes that need to run on a schedule, run in the background, or be alerted to shut down when the whole application is shutting down (whether they need to clean up after themselves or do a flush, etc). Spring has all that management baked into their application container, so using some simple configuration annotations you can register methods to be called when the application starts or stops, register methods to be executed on some schedule, etc.

2

u/[deleted] Nov 28 '15

Pleeease do not use gray text for the main text of your article.

5

u/BarneyStinson Nov 27 '15

My experience with Spring is similar. I especially don't like that people in my company seem to think that Java applications have to be written with Spring. It introduces so much unwarranted complexity just so you can @Autowire everything.

2

u/djhworld Nov 28 '15

I'd agree with you if you're just using the Spring DI container and no other features, Guice, Dagger et al do a similar job with less dependencies.

I think the key benefit of "core" Spring has is it comes with other features too

0

u/BarneyStinson Nov 28 '15

True, Spring brings a lot of features. But I am opposed to including dependencies before you really know that you will need them. Especially if it is a framework.

0

u/Sophrosynic Nov 28 '15

But think of the time savings!

2

u/georgesovetov Nov 28 '15 edited Nov 28 '15

When I was taught first basics of Spring, I immediately started to hate it.

Java, C# and especially C++ give us so much ways to make code safe and maintainable. But no, we use Python and check every parameter in every function. We use Spring and make tests that take minutes to run or even run application itself and waste minutes just for startup. Everyone read Code Complete but most of them forget all its wisdom after book is closed.

1

u/dpash Nov 29 '15

A common anti pattern with spring and integration tests is accidentally creating a new context for each test class instead of reusing the cached context. I've cut minutes off my build by making sure it wasn't rebuilding the object graph every time.

1

u/dccorona Nov 29 '15

you run integration tests on build? how are your integration tests even close to reliably available for every single build?

1

u/dpash Nov 29 '15

If you're starting a spring context they ain't unit tests.

1

u/dccorona Nov 29 '15

Sure, but if you aren't testing an integration point, are they really integration tests either?

1

u/dpash Nov 29 '15

I'm integrating classes together, so yes. They're not unit tests because you're not testing a small unit i.e. a single class.

1

u/djhworld Nov 28 '15

I don't think Spring is so bad, you can write pretty neat applications without having to write XML.

I think the author's problem isn't with spring at all, it's the fact that his corporate banking suite of applications has become too unwieldy for him and his team to manage. His argument that the magic and XML is the culprit is just a symptom of a wider problem.

I'd be interested to hear what his ideas are to change it, because it sounds like he's wanting to do a root and branch rewrite.

1

u/theoriginalanomaly Nov 28 '15

I like java, so it isn't java hate, but their Web stuff ugh. They seem to have a very opinionated framework.

1

u/sazzer Nov 28 '15

Spring is fantastic - for certain scenarios. I'd never advocate using something as big as Spring inside a small library. I use it all the time for writing applications, and for wiring up all of the components. Heck, I even once wrote an application - to read from one JMS queue and write the same messages to 5 different queues - using Spring Integration without a single line of Java code involved. It was all in 3 XML files for the entire project - pom.xml, web.xml and context.xml - and that has been working flawlessly for a few years now.

However, if I was writing a smaller library to be shared between other code, I'd never pull Spring into it, because Spring is large, and opinionated about how things work. I've always seen it as being the framework that you pull other things into instead of the other way around.

1

u/Myzzreal Nov 28 '15

Spring is powerful and gives you what you need to do things, but I feel like it fails horribly on the KISS principle.

0

u/cyrax6 Nov 28 '15

You must have some awful weather. Have a cup of coffee on the Indonesian island. (All puns of course).

0

u/jiffier Nov 28 '15

Spring suffered all that some years ago. But nowadays I honestly find it easier and faster to create a webapp in spring boot than in php. Funny thing is that spring aims at making things simpler in each release, while php world is aiming at making things more complex in each release.

-35

u/[deleted] Nov 27 '15

Only the fags in ##java use Sprint and love it (tjsnell and cheeser and the other assfriends)

Spring is a piece of shit, and they love that.

0

u/[deleted] Nov 28 '15

[deleted]

6

u/stormcrowsx Nov 28 '15

The manual for spring takes a week to get through and takes 6 months to get a junior to competently wield it. Its not some little man page.

2

u/[deleted] Nov 28 '15

"I don't want to read your stinking manual. Just fucking work, you piece of shit, my plane to Fiji leaves in 3 hours."

0

u/[deleted] Nov 27 '15

[deleted]

4

u/id2bi Nov 27 '15

Why would you want to compile Spring to use it?

0

u/[deleted] Nov 27 '15

[deleted]

21

u/[deleted] Nov 27 '15

The best way to have your opinions taken seriously is by avoiding phrases like "sucks balls" and "is retarded."

Also your post is rife with "I DONT LIKE IT SO NO ONE LIKES IT" bias. Tons of people love Java. Are you blind?

6

u/zexperiment Nov 27 '15

This account exists to spew vitriol every time someone mentions Java.

4

u/_INTER_ Nov 27 '15

It's also his _17 th account.

3

u/tweakerbee Nov 27 '15

0

u/[deleted] Nov 27 '15

[deleted]

3

u/tweakerbee Nov 27 '15

I did, you cherry picked the top two results, but let's look at the four results underneath:

Why I hate ASP.net Gamers With Jobs

Why I hate ASP.NET MVC Joonha's Blog

MVC sucks | The ASP.NET Forums

I fucking hate ASP.NET MVC : offmychest - Reddit

You said "no one is saying this". That's pretty much untrue for everything.

0

u/[deleted] Nov 27 '15

[deleted]

3

u/immibis Nov 27 '15

I dunno, how do you C# guys manage to code without throwing up every 10 seconds?

0

u/[deleted] Nov 28 '15

[deleted]

0

u/immibis Nov 28 '15

Java isn't 1990's technology.

Java is a modern, properly designed language.

In contrast with C# which is pathetic useless micro$oft crap from the 90's and lagging 20 years behind, with a roadmap until 2020 which is basically NOTHING but catching up with Haskell from 2005.

how does it feel to work with 1990's technology, in 2015?

1

u/nutrecht Nov 28 '15

Oh jeez... I hate having to repeat myself over and over

I really don't believe you "hate" repeating yourself seeing how much you seem to enjoy repeating yourself :D

0

u/[deleted] Nov 28 '15

[deleted]

1

u/nutrecht Nov 29 '15

I know. I'm just poking him.

0

u/[deleted] Nov 28 '15

[deleted]

1

u/nutrecht Nov 29 '15

Oracle paid for surgery. I have had my stomach removed.

5

u/tomservo291 Nov 27 '15

... on windows? gag

1

u/exneo002 Nov 27 '15

Can't you host on linux now thanks to Roslyn?

5

u/tomservo291 Nov 27 '15

Until MS fully opens up and makes their stuff work front-to-back cross platform, I wouldn't go there with a ten foot pole.

It's great they're open sourcing their stuff and working with Docker to get .NET Core running on *NIX, but they're a long long way from being truly cross-platform for their full toolset, if ever at all.

You can't look at them and say hey their developer tools are free, while the only place you can deploy the stuff (Windows/Windows Server) is very much not free, and very very expensive.

1

u/exneo002 Nov 27 '15

Thanks for clearing that up. Not to mention windows sucks.

0

u/[deleted] Nov 27 '15

[deleted]

1

u/mzial Nov 27 '15

You'll have a very hard time convincing people to switch to C# when it's controlled by Microsoft and practically not cross-platform, even if the alternative is less 'awesome'.

So, elaborate, please.

-1

u/[deleted] Nov 27 '15

Oh, btw, Linux is free only if your time has no value.

If you're so stupid that you can't use Linux then yeah, feel free to keep sucking Microsoft's dick.

3

u/agliev2 Nov 27 '15

agleiv_17 gratefully accepted both C#'s and F#'s thick penises into his distended throat and anus.

1

u/askoruli Nov 27 '15

Can always count on you having the most downvoted comment in pretty much any java post.

2

u/nutrecht Nov 28 '15

I actually check his account every now and then to see if there's any interesting Java news I missed. It's really convenient.