Ask HN: Scala vs. Kotlin?

12 points by rajeshp1986 ↗ HN
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 ] thread
I tried Scala and gave up: it's too cryptic, it gives too many opportunities to do "clever" hacks and leave you scratching your head trying to find out what the code is supposed to do.
I'd also be a little wary of Kotlin unless its for Android dev. Java is catching up a lot with Kotlin and it even looks like its going to have a much more powerful pattern matching story than Kotlin https://mail.openjdk.java.net/pipermail/amber-spec-experts/2...

I'm not sure if its worth the constant context switching to pick up Kotlin for backend development personally.

I fear Kotlin might go a similar route as Groovy. That said, Groovy never got so much traction, so maybe not, but Kotlin definitely seems to be losing its momentum thanks to Java's fast progress.
Where do you get the idea of Kotlin losing momentum?

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)

Scala is complex and interesting but perhaps more research than industry. If your goal is to learn fancy programming languages, I would go with Scala. If your goal is to do side projects not in Java but still using the JVM without thinking too much about the programming language, I would pick Kotlin.

I recently enjoyed learning Rust, but it's more low level which you may enjoy or not.

Chiming in because the two extant comments are dismissive of Scala.

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.

I've been using Scala for a number of years. Frankly, I'm very wary of recommending it to anyone. The job market seems to not be growing (if not shrinking, as Spark-based projects are largely moving to Python now) and the community is focused on complex and esoteric ideas for solving mundane problems ("purity" over practicality). You're likely to work with people like that on your next Scala job. It's great if you dig it, but sucks if you just want a boring language that allows for getting things done.
That have been my experience as well. It requires too much of time dealing with non essential issues. Been doing Scala for spark development for a bit, but I get this vibe, that may be I should go back doing mundane Java or learning either Go/Rust.
Agree completely with everything you said and your observations regarding job market. I’ve been doing Scala for several years and I also would not recommend it to anyone unless they have a deep desire to do pure FP(functional programming) on the JVM. The ecosystem/libraries are unnecessarily complex IMHO.

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.

7 month ago received an offer to join Scala project. Before that worked with Java and Go. I would say Scala is an amazing not just language, but an ecosystem. As a language, it’s very ergonomic and allows to do complex things with less boilerplate. So if you really interested in programming, learning new concepts - I would recommend to try it. If you want just to do boring stuff for money - Java and Golang. Regarding Kotlin - it doesn’t intersect with Scala, because mostly used for Android and back-end with Spring or other Java frameworks. Scala is mostly used for distributed systems, big data and applications with complex domain.
I don't think it's worth going from Java to Kotlin unless you have a real pressing reason. JVM languages have come and gone. None of them present enough of an improvement to leave the metric crapload of legacy Java code behind.

IMHO, for static typed lanaguages the most practical are Go or Typescript (if you wanna count that).

I think it’s pretty simple why you’d want to use Kotlin on the server; full stack Kotlin development: 1 language for both Android and Server(lowers time, costs, and you can share code).

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)

The question isn't really if Kotlin is better or not. It is whether or not people will end up using it. And it doesn't really look like it's going to be a winner in the market.
The simple fact that Kotlin is an officially supported language for Android app development will guarantee people will use it, in my opinion. It will almost definitely do better than Scala in the long run.
> IMHO, for static typed lanaguages the most practical are Go...

Could you share your criteria for "practicality"?

Some combination of job availability, industry usage, and likelihood of being around in 5-10 years.
First I would ask, what's your motivation?

- 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.