6 ms·
Learning Spring with Kotlin – Sprint 0
- jillesvangurp 6y agoI've been using spring and Kotlin together for nearly 3 years. Since then, a lot of Kotlin specifics have crept into Spring. Also, there's an effort to move to a fully declarative Kotlin DSL for driving spring (kofu), which gets rid of basically all anotations, AOP processing, and other magic that makes spring both nice and hard to debug. At this point, if you are using Spring and not using Kotlin: you are doing it wrong. You are missing out on a ton of stuff the Spring people did to support Kotlin. Yes Java is still supported but it is increasingly in the same way that Google hasn't completely deprecated Java for Android yet despite that obviously very much being a second class citizen in that ecosystem. In short, if you are a conservative institution like a bank and evolving your tech stack at a glacial pace; yes you can still use Java. Everybody else, you probably should be using Kotlin. My advice to anyone looking to do this is: 1) Do it, it's easy and you end up with better code. You can start simple and mix Java and Kotlin code. I would advice starting with some tests or some new features. 2) Beware of the java idioms and cruft in Spring and do things the Kotlin way. So, DSLs instead of annotations + AOP, co-routines instead of spring flux, immutable data classes instead of java beans, etc. 3) Spring has a lot of stuff and not all of it is great or even good. IMHO the added advantage of e.g. spring-cloud or spring-data is very limited and sometimes it's just very limiting/backwards. I ripped out spring-data on several projects where people naively supposed it was the easiest/best way to interact with Elasticsearch. It turns out it is neither. Spring cloud sounds nice until you realize most of the stuff you need is supported in the amazon driver but yet not exposed in spring-cloud. Also all the code samples on Amazon are for their own driver and not for spring-cloud. 4) Re-assess if you actually want to go anywhere near hibernate. IMHO it made a lot of sense when java beans were hard to write. Kotlin data classes take away most of that pain and there are some nice alternatives. Also, you should be using non blocking IO for talking to your DB and hibernate is still stuck on blocking IO. That in itself is a good reason to not use it on new projects. Once you get a bit further, you'll find yourself wondering if ktor would work. The answer is probably yes. It's actually pretty good. Spring does a lot of things but ultimately do you really need all of that and the associated complexity?
- humbleMouse 6y agoDo you have any thoughts about Groovy?
- alexhutcheson 6y agoIf you're using Groovy you might as well use Grails[1]. It's built on top of Spring Boot but gives you Groovy interfaces to most of the things you'd care about. [1] https://grails.org/ https://grails.org/
- jmchuster 6y agoas much as I love Groovy, it is sadly essentially a dead language. None of the language bugs and issue I have with it will probably ever get fixed. Kotlin has learned a lot of things from Groovy, and carries on a similar tradition of "java with syntactic sugar", though they've taken it slightly farther. And with the support of both JetBrains and Google behind it, it actually gets the fixes and improvements it needs, combined with all the growing community and overall momentum.
- jillesvangurp 6y agoWith Kotlin out there, groovy is completely redundant. Also development seems to have stalled a little. I removed it from a few projects I inherited to simplify my life a couple of times.
- krakatau1 6y agoI still go with Groovy for scripting and tests with Spock. Scripting is better because Kotlin doesn't have simple dependency management like Grape and compilation speed is way faster than Kotlin's. One of Kotlin's downsides is compilation speed and kts (kotlin script) is even slower. Also, Groovy still has ton of utility methods in GDK not matched in kotlin stdlib. Other than that, I'm sad to say, Groovy is dead or in process of dying. I'm seeing companies rewriting Grails apps to Spring Boot and switching to Kotlin dsl in Gradle. It's a shame really, such a fun language to program in.
- humbleMouse 6y ago
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- fergie 6y agoSome guy writes an article where he says he is thinking about learning Spring with Kotlin and this is worthy of the front page of Hacker News??