9 ms·
A question for HN - I like Java a lot for the ‘http API talking to SQL database’ usecase, with my goto for that being dropwizard or spring boot. I’ve only ever
by davnicwil 6y ago
A question for HN - I like Java a lot for the ‘http API talking to SQL database’ usecase, with my goto for that being dropwizard or spring boot.
I’ve only ever looked at Kotlin code in blogposts, haven’t ever actually used it. I’m probably at least a few years behind on its feature set, but I am aware of all the great features Java has added in that timeframe, many no doubt inspired by Kotlin!
Would you advise me to use Kotlin over Java building a new API from scratch in 2021, given where both languages and ecosystems are today? Why or why not?
- marton78 6y agoFor your use case just use PostgREST.
- dbsmith83 6y agoMy team uses Kotlin + Dropwizard + Postgres a lot. I would absolutely recommend trying Kotlin out on your next API. You will find the code very easy to learn coming from Java, and it is honestly a joy to work with compared to Java. You will find your code much more concise yet more readable. Also, IntelliJ gives you all kinds of hints for how you can make use of Kotlin language features. You can also easily handle nulls in Kotlin, since values have to be explicitly nullable in order to be able to have one. This is great for your application model layers. The val/var paradigm is nice so you can stop having to remember to write 'final'. If you ever get stuck and don't know how to write something in Kotlin, you can just write it in Java and either use it, or just paste the code in IntelliJ and it will convert it to Kotlin. Lastly, Kotest + Mockk is awesome--super readable testing.
- aweiland 6y agoWhat do you use at the database layer? Hibernate, or something lighter, and more Kotlin native, like Exposed?
- dbsmith83 6y agoWe use MyBatis annotations. Usually, for our specific use case we are calling a Postgres sproc. It was a little tricky for one part since we have a json type column, so we had to create our own little pgobject mapper which took a day to figure out how. Other than that, it has been a breeze.
- ta988 6y agoYou have to consider not only the language but what the team working on it will look like. It is still a bit hard to find server-side kotlin devs. On the other hand in my experience, Java devs pick up Kotlin really quickly (as do Python devs interestingly whereas they struggled with Java). I'm a huge proponent of Kotlin on the server side, less on frontend (JS) side. If you go with Kotlin and Spring Boot, Micronaut or even just Ktor,you'll likely not regret the choice. (I have no experience with DropWizard). Now if you choose Java it will not be a horrible choice either, and it is not too hard to convert to Kotlin later if you need/want to. I've heard cases of people going back to Java a few years back, mostly for compiler performance reasons, but there has been a lot of effort on that recently. And while compiling Kotlin is still slower than compiling Java, the fact that you can divide things more easily in multiple files and incremental compilation compensates in most cases (except of course in the case f a clean build).
- BoorishBears 6y agoStrictly imo, using Kotlin with Spring Boot defeats the purpose if you're trying to get away from traditional Java web frameworks (didn't think I needed to spell this out due to the next sentence, but HN gonna HN). Kotlin is a chance to get away from the cruft and annotation magic of traditional Java. I use Ktor and it's everything you need for a modern API (and can be deployed as a WAR if that's why you want Spring Boot) Ktor's API that will be familiar to anyone who's used similar "neo-web frameworks" in other languages like Gin or Express, and it allows you to architecture your app in a way that makes sense to you (so if you need DI, you can bring in something like Koin, but you're never compelled to by the framework)
- scaladev 6y agoI thought ktor was a toy, but apparently YouTrack (JetBrains' alternative to Jira) is built on top of it: https://www.jetbrains.com/help/youtrack/standalone/Third-Party-Software-Used-by-YouTrack.html#YouTrack_Back-End_Libraries https://www.jetbrains.com/help/youtrack/standalone/Third-Par...
- 6y ago
- vikingcaffiene 6y agoI've been writing Kotlin professionally for the past 2 years. I'd highly recommend it as a worthy successor to Java. It's very powerful and thoughtfully designed. Java just feels so old and clunky after using it. I've not had the pleasure but I hear Scala is great too.
- pjmlp 6y agoSo is there a Kotlin Virtual Machine already available?
- vikingcaffiene 6y agoIt runs on the JVM. That's one of its selling points. :)
- pjmlp 6y agoSo Kotlin is useless without Java then, unable to stand on its own.
- seanmcdirmid 6y agoIt’s a great language to use instead of Java...especially for things that have to run on the JVM, or Android.
- pjmlp 6y agoSyntax sugar on the JVM, as it is never to be more than a blip on the Java Virtual Machine. As for the Android Runtime, Android team is gatekeeping Android Java on Java 8 subset on purpose, as means to serve their political games to push Kotlin no matter what. Kotlin without godfather Google will just fade away.
- seanmcdirmid 6y agoI have no idea about any politics involved, but Kotlin is a really well designed language. Fixing Java piecemeal as has happened so far just seems like an impossible task, while the JVM is flexible enough to support it.
- lordnacho 6y agoI'm doing a kotlin project. You won't find it hard or unfamiliar if you're used to Java. You still got gradle, and you still can use whatever java lib you want. It just feels much nicer in kotlin. Just jump into it, you can swap back if it doesn't suit you.
- brabel 6y agoI've been using Kotlin in the backend since 1.0 (4 years now??) and it's great, but it does have a few small annoyances. We still have most of our codebase in Java and routinely, we create new Java code instead of Kotlin for everything, interestingly enough (mostly because when a module is already written in Java, it's mostly a source of confusion to add a few Kotlin files - so we tend to only use Kotlin when creating new modules that are fully Kotlin). Also, some of our developers just don't seem to have enough abstraction power for the higher level of code you can write in Kotlin (specially when you start using things like Kotlin builders to make code "prettier", or just abust a little bit the "everything is an expression" feature to completely avoid separete statements - e.g. functions without braces). People moving from Kotlin back to Java is not unheard of: https://blog.allegro.tech/2018/05/From-Java-to-Kotlin-and-Back-Again.html https://blog.allegro.tech/2018/05/From-Java-to-Kotlin-and-Ba...
- crossroadsguy 6y agoKotlin outside of Android is still a fancy new thing. I am not commenting on its capability but the trend. (On Android however it seems it's pretty much the only thing now. I am finding it the hard way now when I am looking for a job after staying on a project too long where things are still 98% Java) It's an amazing language. Just try not to write "Java code" (as in the Java way) in Kotlin (like many Android devs I see doing).
- sorokod 6y agoI work in a fintech company, most of our backend is in Kotlin with "legacy" functionality in Java. Can't think of a single developer that would choose Java over Kotlin.
- chrisseaton 6y agoI'd choose Java over Kotlin. The benefits of Kotlin seem minor - mostly syntactic sugar - and the tooling is more limited than Java. They seem to solve problems with kludges (like their coroutines are really just state machines in JVM bytecode, which creates issues like irreducible control-flow) rather than properly engineering solutions like Java try to do.
- sorokod 6y agoJust sharing my experience, to each his own.
- balfirevic 6y agoHow did Java (as opposed to JVM) try to properly engineer solution to the problem coroutines were created to solve?
- jsiepkes 6y agoProject Loom: https://openjdk.java.net/projects/loom/ https://openjdk.java.net/projects/loom/ The view being that async-await leads to a "What color is your function" problem ( https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ https://journal.stuffwithstuff.com/2015/02/01/what-color-is-... ).
- balfirevic 6y ago"As opposed to JVM" You don't have to convince me that green threads are far superior to async-await - I already believe that. But that's not something Kotlin (nor Java, on the language level) could have solved.
- johnnycerberus 6y agoKotlin never appealed to backend developers (based on job ads, new open-source projects in the domain). Data pipelines, concurrency and streaming are becoming more and more part of what a backend dev should know. Instead, I've noticed that Scala is used in many systems where Java historically was less ergonomic for the task. Spark, Delta, Deequ, Scio, Finagle, Flink, Kafka, the Typelevel & ZIO ecosystems, Akka are some of the examples. Using Kotlin as a sugary interface to Spring Boot? Maybe for some that would be an incentive.
- Pxtl 6y agoI think a big part of the appeal of Kotlin was that Scala was impractical for use on Android so Kotlin slid in as "the missing pieces" of Java.
- jsiepkes 6y agoYeah also somewhere after Java 7 (I think) Java stagnated because the next version was too ambitious (stuck in development-hell). To get back on track they cut a bunch of features, labelled it Java 8 and moved Jigsaw (the biggest hurdle) to Java 9. After this they also moved to the fixed release cycles.
- pjmlp 6y agoJava stagnated because Google torpedoed Sun, left it sink without bothering to own Sun, Oracle was the only one that bothered to keep their buy offer (IBM withdrew theirs), and and to spend a couple of years setting the house straight. Yet, there are no FOSS language that matches JIT and GC capabilities of the JVM. Looking forward to the KVM, if Kotlin is so great.
- pjmlp 6y agoBecause Google as Kotlin's Godfather is stagnating Android Java on purpose, on the proper JVM we don't have such constraints.
- 6y ago
- surfsvammel 6y agoTry it out! I’ve been building with Java for about 13 years and just started playing around with Kotlin last year, and I must say that I fell in love immediately.
- prpl 6y agoI did a dropwizard and kotlin project around 1.2.20 (3 years ago) and it was fine even then, with some minor rough edges. I would imagine everything is fine now.
- jitl 6y agoKotlin on the server is the dream
- mraigig 6y agoI recommend having a look at http4k as an alternative to Ktor and Spring as well.
- yes_but_no 6y agoI would, main reason being calling Java from Kotlin is seamless. It makes most things easier by being expression oriented and having less verbose yet familiar syntax also saner type system. So you can just use it as better Java. If you want to go further you can also use other nice features like suspend functions, hot/cold channels, sealed classes.
- pjmlp 6y agoOther than Android, where Google is pushing Kotlin no matter what, I would use the platform's official language, Java. No need for FFI, additional IDE plugins, it works across all Java IDEs, no need for idiomatic plugins, annotations to make code understandable by the JVM, full access to JVM opcodes without constraints or special cases, and it will be around as long as the Java Virtual Machine matters to the industry.
- vbezhenar 6y agoYou can't go wrong with either choice. Both languages are mature enough to be used in production. I, personally, would use Java, but that's just my preference. Actually you don't really need any new features to write useful programs. They might help, but they are not necessary. My advice would be to learn both languages and use your own judgement which one you would like more.