DEV Community

Graham Cox
Graham Cox

Posted on

... Or how I learned to stop worrying and love the magic

There was a time in my career when I'd want to do everything myself. I'd rationalise it away as learning how to do things, but I'd be much happier if I was doing things myself rather than depending on others to have already done it.

This ranged from small things - 3d maths libraries, for example - up to huge things - I once wrote a fully compliant websockets server using only Java NIO!

Over time I got less attached to this and more embraced existing libraries. After all, they were written by very clever people, and already did everything that I needed. For example, using the websockets support in Spring instead. This, obviously enough, made me significantly more productive - reinventing everything is a slow process, and a relatively pointless.

However, I still shied away from "magic" if I didn't write it myself.

Side note: what is magic? It's anything where the exact outcome works but you can't immediately see why or how it works.

This meant I was happy to use Spring, but stayed away from Spring Boot - preferring to wire everything up by hand so I could see it all.

And, over time, even this has changed. I recently wrote a mock server for work, using Spring Boot, Spring Starter, Spring Shell. Heck, I even used component scanning. (That still does make me feel dirty, but for what I feel are very good reasons - it's very difficult to scale up to medium or large systems and still know how it works...)

And you know what? The magic isn't scary. It works. It does exactly what it's meant to, and it lets you do everything else.

That mock server, from start to end, too about 3 hours. Old me would have spent a week on it! How's that for productive...

Top comments (2)

martinhaeusler profile image
Martin Häusler

Spring Boot is really awesome. Once you understand how it works (the answer is either "component scan" or "dynamic proxies" 95% of the time...) you could technically implement it yourself. The concepts are not too crazy. But Spring does a really good job. I've been continuously using it for 3 or 4 years now and have very little to complain about. When it comes to building trust into the Spring framework specifically, the nice thing is that there is a huge community behind it. No matter how obscure your problem may seem, there's very likely a stack overflow answer for it. And if there isn't, a well formulated question usually receives an answer within a couple of hours. The other aspect is that Spring is designed to be extremely configurable. So if you don't like a certain part of it - well, swap it out for something else!

All of that being said, Spring Data really IS black magic (i.e. runtime byte code generation) but hasn't failed me yet. Spring Security has a harmless look to it, but boy, try to debug why your call is being rejected, it's like searching for the literal needle in the haystack.

Overall I still like Spring a lot, in particular in combination with Spring Boot. That wasn't always the case. I hated it passionately when I first got into contact with it. The key turning point for me was when I realized how the IoC container principle worked and - in particular - how to properly USE it and when not to use it (the latter part took me a really long while!). From that point onward, everything else kind of followed and made sense to me. I haven't ever looked back since then.

grahamcox82 profile image
Graham Cox

I'll be honest, I tend to have the opposite problem with Spring.

Their stuff generally just works. Their documentation is fantastic. They have examples of most things that are easy to understand.

This means that when I have a problem with it, it's often one that hasn't come up before and doesn't have a simple answer. Because if it did then it would be in the aforementioned documentation or examples.

I've even had to raise bugs against Spring because of exactly this - wanting to do something that should work but didn't... (And, generally speaking, they're very fast to respond to those too)