Hi All, what would you recommend to learn Kotlin f...
# getting-started
r
Hi All, what would you recommend to learn Kotlin for someone who's been coding in Java with Spring for 5 years. I started the Kotlin Koans, Atomic Kotlin, and Kotlin courses in JetBrains Academy but none of those seems right to me. Is there any other option?
c
My recommendation is always to just go build something non-trivial. Take a project you’ve built before in Java, or start with an idea of something that interests you, and start trying to recreate it in the new language/framework. By building something you’re familiar with and excited about, you already know the details of how the app/system works and should be structured, leaving you to just focus on learning the parts that are new. For example, I play a lot of board games and like to build an app for tracking player’s scores, and have probably built this thing a dozen or more times at this point. But I already know what fields I will need to edit, how the business logic works, where the data needs to be stored, navigation, etc. So when learning a new framework I really just need to figure out how to work with the UI and the database that is specific to the framework I’m trying to learn.
m
Are you talking about Kotlin or Android? Because for a Java dev switching to Kotlin should be very easy. Learning android development coming from backend is a different story
s
@Roque Sosa What do you mean by "not right for you"? I learned Kotlin by reading "Kotlin in Action", doing the Kotlin Koans (the first time round the Collections exercises stopped me) and then converting an existing Java project to Kotlin. So what you did sounds good. Where's the problem? To me Kotlin feels like a better Java, so it doesn't feel that different just better in many smaller and a few bigger ways. The big new thing is nullability, but then there is a push to immutability with using
val
over
var
and immutable collection interfaces where ever possible. Add here and there an extension function and if you have a function taking a lambda try to make it
inline
. Use `data class`es for your DTOs and get used to collection processing (a skill that is super transferable to stream processing in Java) and your code should be pretty decent Kotlin. Concepts like data classes, sealed classes/interfaces and a switch expression have made it into Java right now. (ok, technically speaking the aims of records and data classes are not quite the same, but since I mostly use data classes with all
val
properties they are quite the same in (my) practice.) (As long as your not working with a reactive codebase you can set aside coroutines. Those take a bit longer, but so does learning reactive programming in Java.) I've worked with Java devs coming to Kotlin projects in the past and treating Kotlin as Java with inbuild Lombok + nullability is a perfectly fine first step!
👍 1
a
@Roque Sosa just start code in Kotlin.
r
Thanks all, what I didn't like about the ones I listed was that they had isolated exercises that as long as I passed the tests were done, but it didn't correct me and showed me what was the best Kotlin way of doing it (unless I manually checked the solution for each). Yesterday I started reading Kotlin in action (great book so far, thanks for the recommendation) and rewriting an old java application I had.
👍 1
j
@Roque Sosa look at the #advent-of-code channel for anecdotal chats on different ways to implement things. For a more thorough exploration, I recommend the book and video series referenced in #java-to-kotlin-refactoring