DEV Community

Discussion on: Back and forth from Scala to Java

Collapse
 
mategreen profile image
matej

Hi,
I suggest you to use Vavr. I use it extensively for all Java projects.
I also prefer Immutables over Lombok, but it's just about the personal taste.

Collapse
 
josealonso profile image
José Ramón (JR) • Edited

Gerbrand @mategreen , thanks a lot for your comments!! I didn't know the vavr functional library. It's like Scala, amazing !!
Based on my investigations, I learned that only the Immutables and vavr libraries provide real immutable objects. I really like vavr, since it removes a lot of boilerplate code, it feels like Scala and doesn't use annotations. But I'm afraid it requires a big learning curve for many Java programmers. I met a Scala programmer who had to rewrite in Java an existing Scala project, because his company didn't find Scala developers. He told me he uses something similar to what vavr provides. I will tell him about that library.
My use case is refactoring a legacy code which is in Java 8 or 11. I didn't start the project yet, but I'm learning Kotlin in-depth, because I think it's easier to learn than Scala (or the vavr library) and it was designed with Java interoperability in mind.
Kotlin collections are read-only, not immutable. But there is a mature kotlinx.immutable library that is really easy to use. Kotlin can also be used in Spring, as you know.

To sum up, my plans for migrating a legacy Java code base to something more maintainable and functional consist of using Java and Kotlin at the same time. I think having immutable objects by default is crucial, like you have in Scala. Fortunately, you can have that in Kotlin using the above mentioned library.

You say you use vavr extensively for all Java projects, but you also use Lombok. I'm curious to know for what projects you use vavr. Are they only personal projects and if not, how do you achieve your team to get familiar with functional programming ?

Thanks for your insights.

Collapse
 
mategreen profile image
matej • Edited

sorry for my late answer.. yes, you're right! that's what exactly happened in our team. Due to re-org we merged with another team that started project in Scala (namely in Play framework) and we had to switch to Java as we didn't know anything about Scala (and functional programming ofc) that time. But I really liked it! To be honest, nowadays, it's much easier reason about vavr Futures than Java CompletionStage etc.
btw this book really helped me with FP:
Functional Programming In Java
Our stack is Play framework or Akka Http (now Pekko) and yes, I use Vavr for corp projects.