https://kotlinlang.org logo
#announcements
Title
# announcements
v

vaskir

06/13/2017, 6:52 PM
about the features, being an F# dev for long time, the only thing I really, really miss in Kotlin (after a couple of weeks of learning it 🙂 is pattern matching. Another (less severe one) is a lightweight syntax for unions.
1
p

poohbar

06/13/2017, 7:08 PM
vaskir: I have never ever in my whole career had the need to use pattern matching. It can't be that important.
😆 1
r

roberto.guerra

06/13/2017, 7:27 PM
I miss pattern matching too (and cons).
k

kirillrakhman

06/13/2017, 7:32 PM
I'm working with C# in my day job and I've come to appreciate pattern matching.
v

vaskir

06/13/2017, 7:39 PM
@poohbar that depends on how "functional" you code is. If you use ADTs heavily (instead of class hierarchies with polymorphism), than life without pattern matching is hard. Look at an idiomatic F# code, for example: http://www.fssnip.net/8R/title/Tennis-Kata and it's port to Kotlin https://github.com/sitepodmatt/kotlin-tennis-kata/blob/master/src/main/kotlin/tenniskata/kata.kt
Copy code
let scorePoint score point =
    match score, point with 
    | Advantage player1, player2 when  player1 = player2 -> Game player1
    | Advantage player1, player2 -> Deuce
    | Deuce, player -> Advantage player
    | Points(Forty, _), A -> Game A
    | Points(_, Forty), B -> Game B
    | Points(a, b), A -> normalize (Points (nextPointScore a, b))
    | Points(a, b), B -> normalize (Points (a, nextPointScore b))
    | Game _ , _ -> (* printfn "the game is over!"; *) score
vs
Copy code
fun scorePoint(currentScore : Score, point : Player) : Score {
  return when (currentScore) {
    is Score.Points -> 
      if (currentScore.playerA === PlayerScore.Forty && point === Player.A) { Score.Game(Player.A) }
      else if (currentScore.playerB === PlayerScore.Forty && point === Player.B) { Score.Game(Player.B) }
      else 
          if (point === Player.A) Score.Points(nextPointScore(currentScore.playerA), currentScore.playerB)
          else Score.Points(currentScore.playerA, nextPointScore(currentScore.playerB))
    is Score.Advantage -> when (currentScore.player) {
      Player.A -> if(point === Player.A) Score.Game(Player.A) else Score.Deuce
      Player.B -> if(point === Player.B) Score.Game(Player.B) else Score.Deuce
    }
    is Score.Deuce -> Score.Advantage(point)
    is Score.Game -> throw Exception("Game already over")
  }
}
💯 1
p

poohbar

06/13/2017, 7:47 PM
I find neither of the snippets readable so I would probably implement it very differently. F# is unreadable in general and I am against adding any more fancy features to Kotlin just because they seem cool. There were some advantages that Java was adopting new features super slowly, because fads come and go.
r

roberto.guerra

06/13/2017, 7:53 PM
Sorry, but pattern matching is not a fad. It has been around before Java was a thing. It reminds me of similar messages I read prior to Java adding lambdas. It was seen as too academic, not needed, “hey, I’ve never needed labmdas (in Java) before to do anything, so it probably isn’t needed”. Before I delved into SML, having had only experience with C-like languages (Java, C/C++, Ruby, Python) I didn’t understand what pattern matching was and had pretty much the same attitude. But once I learned SML, F# and Scala, I saw how powerful they could be (along with ADTs). I miss them when I have to do something in JS or Java (or any language without support for pattern matching).
b

bamdmux

06/14/2017, 5:29 AM
Same for me regarding missing features from Elixir/Erlang after we got coroutines
v

vaskir

06/14/2017, 7:16 AM
@poohbar so how would you implement that program in Kotlin "very differently"?