Hello!
I’m currently a University student in my second year and I’ve recently discovered functional programming. I learnt Scala and was really hyped up by the awesome features it had compared to Java, but I would like to learn Android app development in the following months. I also found Kotlin, which seems promising for Android (much lighter runtime library compared to Scala, faster compile-time, zero-overhead null safety, inlined functions and lambdas that lead to improved performance etc.), but I would have a few questions (for which I didn’t find answers searching on the web).
- What is the performance of Kotlin extension functions compared to Scala implicits? (I’m somewhat familiar with both concepts, but I don’t know the underlying implementations of either; I know, though, that Scala implicits can impose pretty big overhead if not used as value classes for a few restricted use-cases).
- Not sure about the current state for this feature, nor for the future state, but a frequent pattern in Scala is having a sealed trait / abstract class that is extended by case classes. Transposing this to Kotlin, it would be to have a sealed interface / abstract class extended by data classes. Right now, as far as I know, data classes cannot extend anything (to avoid breaking the equals function). However, I think this would be a good use case to allow data classes to extend a sealed interface / abstract class (it would be nice to have the compiler check exhaustiveness in when-expressions and still have automatic equals/hashCode/toString). Is this going to be implemented in the future?
- What is the consensus about proper pattern matching in when-expressions? Something like “when(x) { is v @ Tree(Tree(*, 5, *), 3, Leaf) -> println(v) … }”. Is it going to be implemented in a future version of Kotlin, or when-expressions will remain unchanged?
- The “yield” operator seems just too awesome to have it missing from Kotlin. What’s the status on this?
I am aware that the Kotlin development team is trying to ship a stable 1.0 release of the language and will not add new language constructs before that, but I’m curious whether these features are planned to be added in future releases.
I would really appreciate if anybody took the time to answer these questions. Thanks!