Thursday, October 14, 2010

Spring Aficionados vs. Spring Bashers

The Spring Applications Framework has been an essential and powerful platform for Enterprise Java development for many years now. Yet, surprisingly, every now and then heated discussions still spark in various forums and blogs regarding its benefits. I find there are two general types of Spring Framework users.

1) Programmers who have always looked for ways to craft better software, to save time and effort, who wrote their own micro-frameworks to simplify, reuse, facilitate... Such programmers never stop learning and are only too happy to find better, more efficient ways. They love to learn from others, and they love to share their knowledge. Most importantly, they don't buy into the "silver bullet" dogma and tend to critically investigate before deciding whether the solution suits the problem at hand. Many of such programmers are also plain "lazy" - in a good way: they hate having to tediously write the same [spaghetti] code over and over again, working long hours on something that does not involve creativity or bring artistic satisfaction. These people are proud of their craftsmanship, and they appreciate good code when they see it. Such folks embraced Spring as soon as they first experienced it (tried and understood it!) - mostly because the framework was addressing all the concerns any good programmer was already passionate about. It didn't matter whether they found Spring on their own or were introduced to it by a coworker. They did not need to be convinced, they already where in that boat. The best part was that the framework had turned out absolutely non-invasive. Any developer or team could choose which parts of it to use. The only basic condition was: program to interfaces, use dependency injection and POJOs (vs. being restrained by clunky combersome interfaces defined by some specification), strive for quality... These are all just some basic principles of good programming, Spring or no Spring... One really has to dislike chaotic disorganized programming to be a Spring aficionado.

2) People upon whom Spring was forced by some architect/manager/new hire/etc. - when they least expected. Normally, such folks felt quite comfortable with the tools and methodologies they used on the daily basis. Or simply didn't care one bit what they used. (Not all, of course. I don't want to offend those who did care but simply loved the EJB2 spec. :-)) They were rarely inclined to improve anything or change the status quo. (Otherwise, their curiosity alone would have led them to a discovery of the Spring Framework much earlier.) For such people, Spring was "just another framework" that they didn't need. Many of them instantly rejected it without even trying to understand it. For many, it was an ego issue. They had been doing something for years - often holding senior positions in their organizations - only to have some "new guy" to tell them (and everyone who'd listen) that there was a better way... Some of those people eventually took their time to investigate with an open mind. Some never did, they still don't really know what Spring is and how it may be used. And some continue to bash it any chance they get. You'd hear them with all seriousness "comparing" Spring to... Struts (apples to oranges), talking about Spring getting more "bloated" with each release, Spring configuration or code being unreadable (as if it is the framework's fault not the particular developers'), etc. They are the ones who produce bad Spring-based applications, and then blame it on the framework itself.

Yes, I love Spring. (Not sure if that was clear...) I love it for its elegant programming model, non-invasiveness and granularity that allows me to use the parts of it I need for any given application. Just choose what suits your problem and include that into your solution, nothing more. That is something the Spring bashers seem to have never learnt about the framework. No, Spring is not a silver bullet. It is not supposed to solve all your problems. It is there to significantly simplify enterprise Java. It allows you to freely choose between (and painlessly swap if necessary) various implementations of different technologies, it encourages the better programming practices - for those who care, and it gives developers many powerful tools that they may use if they choose to.

Finally, to answer some critics, Spring does not lock you into using vendor-specific (e.g. SpringSource) implementations of anything. It makes it easier to swap between the available options.

I should mention the obvious: using Spring by itself does not ensure good results. One should still be a good programmer to write good code. One must study and understand any framework or tool before applying it. (Needless to say, right?) An incompetent programmer who was told to use Spring would still write an incoherent, bloated application with countless unnecessary dependencies and couplings, with unreadable configuration and source code. One should not judge the Framework based on such poor samples created by those who simply can't design and code.