about the features, being an F# dev for long time,...
# announcements
v
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
vaskir: I have never ever in my whole career had the need to use pattern matching. It can't be that important.
šŸ˜† 1
r
I miss pattern matching too (and cons).
k
I'm working with C# in my day job and I've come to appreciate pattern matching.
v
@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
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
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
Same for me regarding missing features from Elixir/Erlang after we got coroutines
v
@poohbar so how would you implement that program in Kotlin "very differently"?