Thursday, January 03, 2013

Death to Spring!




"I'm tired of the "For Real?" look I get from my developers when they are debugging Spring configuration and they ask my why Spring is better."

"I'm tired of the "For Real?" look I get from my developers when they are debugging JPA/Hibernate issues and I'm explaining to them how JPA/Hibernate simplifies things."

I've been thinking about a Spring Blog post for some time now, and It started back in Feb '12 when I started my new job. There are quite a few Jr. Engineers there, and after noticing they didn't use Maven or Spring, I paused for a second before doing an overhaul. Maven would be nice, and we could certainly use some dependency management, but Spring.. oh Spring…

After being bitten by the chaos, bloat, and sadness that is Spring I had to think long and hard about why I liked Spring in the first place.

Testing.

I can just hear my old co-worker now: "How are you going to test without Dependency Injection?!" 

Besides some nice wrappers around JDBC and a few other APIs, testing is really the only useful thing that Spring did for me. Lets be completely honest, there are only two cases where I want to significantly reconfigure an application: Production use, and Unit Testing (everything else is just a config param change, for which Dependency Injection is WAY overkill).  So stopping to think for a minute I ended up with a scheme where most of my dependencies were created in protected methods, and my unit tests simply created anonymous classes that override the required protected methods. Done.

BAM!

And just like that, no Spring, no wacky half supported ASM / Byte code generating, voodoo that is impossible to debug, breaks when mixed with the wrong framework, bloaty, buggy, complexity. Just override the protected methods and you are testing like a pro. Works great with final variables, you don't have to have a constructor 20 parameters long, no pointless setters, no mystery stack  traces, works with all coverage tools,  just get your job done and move on.



0 Comments:

Post a Comment

<< Home