Ask HN: Scala vs. Kotlin?
I am an experience Java programmer. I am interested in learning picking a new programming language in my spare time. I am interested in static-typed languages. Which one should I pick next? If you have any other interesting suggestions/alternatives then please recommend those as well.
17 comments
[ 2.8 ms ] story [ 46.9 ms ] threadI'm not sure if its worth the constant context switching to pick up Kotlin for backend development personally.
Serious question.
Can Kotlin/JS be a real competitor to TypeScript on the browser? Kotlin Native vs Go? Because if so, Kotlin doesn't have to go head to head against Java to win on the JVM too. (imo)
I recently enjoyed learning Rust, but it's more low level which you may enjoy or not.
I use Scala every day, our current application is written 100% in Scala. We write functional code, but we are not religious about "purely functional" code.
My understanding is that, currently, writing Kotlin means you are almost certainly writing Android apps. If a company chose Kotlin over Scala for a backend/distributed application, I would be astonished. Maybe that is my bias, but Scala is proven and continuing to grow in the distributed space (Akka, ZIO, etc).
Regarding scala being "too cryptic". I felt the same way about Django when I first learned it -- now everyone thinks Django is a breeze. I had the luxury of learning Scala on-the-job, and had great mentors who saw the power of the language and helped me realize it too. Scala can be "fancy", but it can also be simple and elegant, if you learn it slowly.
Frankly, I think my biggest issue with Scala is that I live in North America, and the really interesting products built in Scala seem to be made by European teams.
If you want FP-Lite, I recommend Kotlin, it’s very pragmatic, reasonably functional, and mid way between Java and Scala. I actually converted all my personal projects from Scala to Kotlin, including my framework https://github.com/slatekit/slatekit which took about a 4-6 weeks from the original code base.
IMHO, for static typed lanaguages the most practical are Go or Typescript (if you wanna count that).
And Kotlin multi-platform is making good progress, so potentially you can also build shared code for iOS and JavaScript. Again, it all comes down to time, cost, simplicity.
Lastly, I have to say, after using futures in Java/Scala, async/await in JS, Kotlin got it right with coroutines, channels and flows. I’m not exactly sure what the roadmap for concurrency looks like in the Java world(even with project loom, etc). While Java is moving fast(finally), I think it’s still weighed down by legacy stuff (nulls, mutable code, lack of expressions and more)
Could you share your criteria for "practicality"?
- If you are just looking for a better Java, Kotlin is likely the way.
- If you are looking for a better language that leverages the JVM ecosystem, then, Scala might be the way.
It also depends about what kinds of projects do you want to work with, Scala is a no-go for Android if you are just learning, on the other hand, if you plan to work in distributed systems, Scala is great for that.
The biggest advantage I see on Kotlin right now is the Multiplatform side, we are taking advantage from it to write a library once, that can be consumed by Android, iOS, and our backend services built with Scala (we even want it for the JavaScript side but it isn't as mature as Scala.js).
On the Scala side, it has a very nice ecosystem, with powerful tools that usually get ported to other languages, for example, its the first language where I see good tools for:
- Compile time checked SQL queries.
- Documentation tools that actually compile your code examples to make sure it is correct (even arrow-ank on Kotlin was inspired by tut from Scala).
- Generating JavaScript code that actually works.
While Scala may have had not-so-good tooling years ago, right now is pretty good.
People usually complain about over-complex code, which can be true, but, you can find bad code in any language, on Scala you can choose a path, whether to be pure-FP or pure when practical, and there is great tooling for any side, I personally try to be practical and it has worked quite well over many years (also check http://www.lihaoyi.com/ blog for similar examples).
What I get in Scala that I can't get in other languages I have worked with is usually the confidence that my code works when it compiles.
As of know, I use Scala for backend services, frontend (through scala.js), browser extensions, mobile apps by leveraging PWAs, and even native apps (through GraalVM).
On the job market, every year I see more companies using Scala, and you usually find very competent people which allows you to keep learning, on the Kotlin side, most job posts that I see are for Android than for backend development.