https://kotlinlang.org logo
#feed
Title
# feed
d

Dan T

02/22/2024, 2:54 PM
New post: Spring Rites - a caution against annotation-based web frameworks hacker news link tl;dr; What used to be good reasons for choosing a framework like Spring are no longer good reasons, and tools like Kotlin, ktor/http4k and solid libraries are a better choice today. Because every time IntelliJ adds a complex feature for an annotation framework instead of better function type support or gradle catalog support, a puppy is scolded.
👍 13
🐕 8
👌 1
👏 2
K 3
1
j

Jilles van Gurp

02/23/2024, 10:30 AM
Great article. I still use Spring but I avoid many of the annotations.
How would you know though? And how long would it take for someone new to find the correct answer?
And how will you find out when you get it wrong. Debugging annotation related issues is hard because you have no compile time checks. Your code will compile yet not work and throw some obscure exception at runtime. @Transactional is probably the most abused annotation in Spring. It roughly translates as "transaction pixie dust that makes my tests pass so I just sprinkle it liberally". My code bases is free of hibernate and I bypass Spring completely for database stuff. I have no need for ORMs. A few suggestions: • use koin instead of guice. Dependency injection without annotations. And it's multiplatform so you can use it with kotlin native as well. We actually use it in the browser too with kotlin-js • use the refreshVersions plugin for gradle. You can combine it with using versionCatalogs but it's awesome for staying on top of your dependencies and making informed choices about available updates. I use it on all my kotlin projects. • focus on multiplatform projects: ktor and kotlin-native are a thing. Wasm is coming. You don't need a jvm anymore. There's no need to lock yourself into one platform.
d

Dan T

02/23/2024, 4:18 PM
Appreciate the feedback @Jilles van Gurp! One question I have for you is if you've compared koin to the method of not using a DI tool?
j

Jilles van Gurp

02/23/2024, 4:21 PM
Yeah, I did some DYI dependency injection at some point. It works but using koin is stupidly easy and it encourages people to separate their glue code from their logic, which is something that goes wrong in almost any project without dependency injection. IMHO it's reason #1 why most javascript projects turn into a spaghetti ball.
👍 1
https://blacksheep.parry.org/wp-content/uploads/2010/03/DIY-DI.pdf Old article but still worth reading. Works in any language.
r

rocketraman

02/23/2024, 6:51 PM
100% agree with this. I despise debugging Spring annotation crud. And the version upgrade problem is real -- one of the enterprise apps I work on is stuck on Kotlin 1.6, because Spring Boot 2.x, because enterprise. Some time ago, I created a small framework called
Bootable
(https://github.com/rocketraman/bootable). Its not quite "vanilla", but it's annotation free and it handles only a few concerns: • DI (via Kodein currently), • lifecycle management of application services (startup, orderly shutdown), handling things like kill signals properly • configuring logging • configuration (currently via cfg4k, but planning a migration to hoplite) • some optional modules that allow things like ktor to plug in to the lifecycle maangement I've never regretted using
Bootable
over Spring Boot.
2 Views