Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala vs. Kotlin; Friend or Foe?

oshai
July 02, 2018

Scala vs. Kotlin; Friend or Foe?

Talk in scalapeno 2018

oshai

July 02, 2018
Tweet

More Decks by oshai

Other Decks in Programming

Transcript

  1. What is Kotlin • Statically typed • Multi-Platform (JVM first,

    JS and Native) • Open Source by JetBrains https://medium.com/@octskyward/why-kotlin-is-my-next-programming-language-c25c001e26e3
  2. Side by side comparison Scala val hello: String = “hi"

    var hello: String = "hi" Kotlin val hello: String = “hi" var hello: String = "hi"
  3. Side by side comparison Scala val hello = “hi" var

    hello = "hi" Kotlin val hello = “hi" var hello = "hi"
  4. Case / data class Scala case class Service( name: String

    ) Kotlin data class Service( val name: String )
  5. Null safety Scala var hello: Option[String] = None hello.foreach {

    s => println(s.toUpperCase()) } println(hello.map( _.toUpperCase()) .orNull()) Kotlin var hello: String? = null println(world.toUpperCase()) if (world != null) { println(world.toUpperCase()) } println(world?.toUpperCase())
  6. Implicit class / Extension method Scala object Helpers { implicit

    class IntMillis(x: Int) { def hours() = TimeUnit.HOURS.toMillis(x) } } … 5.hours() Kotlin fun Int.hours() = TimeUnit.HOURS.toMillis( this.toLong()) … 5.hours()
  7. Operator overloading Scala It’s actually methods with fancy names Kotlin

    Limited to arithmetic operators + - \ * 
 etc’
  8. Where Kotlin shines • Java++ - hit the sweet spot

    • Great Java inter-op • Lean • Tooling • Pragmatic - not reinventing the wheel
  9. Suggestions for Scala designers • Let’s be practical: • Binary

    compatibility https://stackoverflow.com/questions/32255023/how-would-i-go-about-parsing-the-java-class-file-constant-pool
  10. Suggestions for Scala designers • Let’s be practical: • Binary

    compatibility • Faster compilation http://www.doodleosophies.com/doodle/30
  11. Suggestions for Scala designers • Let’s be practical: • Binary

    compatibility • Faster compilation • Improve Java inter-op
  12. Suggestions for Scala users • Stick to features exists in

    Kotlin • Make your code readable by all team members