a look into the future roman elizarov
play

A Look Into the Future Roman Elizarov October 12, 2020 @relizarov - PowerPoint PPT Presentation

Kotlin 1.4 Online Event A Look Into the Future Roman Elizarov October 12, 2020 @relizarov A bit of history Kotlin 1.0 2016 Posted on February 15, 2016 by Andrey Breslav Kotlin 1.1 Released with JavaScript Support, Coroutines and more


  1. Kotlin 1.4 Online Event A Look Into the Future Roman Elizarov October 12, 2020 @relizarov

  2. A bit of history

  3. Kotlin 1.0 2016 Posted on February 15, 2016 by Andrey Breslav

  4. Kotlin 1.1 Released with JavaScript Support, Coroutines and more 2017 Posted on March 1, 2017 by Roman Belov

  5. Kotlin 1.2 Released: Sharing Code between Platforms 2017 Posted on November 28, 2017 by Dmitry Jemerov

  6. Kotlin 1.3 Released with Coroutines, Kotlin/Native Beta, and more 2018 Posted on October 29, 2018 by Roman Belov

  7. Kotlin 1.4 Released with a Focus on Quality and Performance 2020 Posted on August 17, 2020 by Svetlana Isakova

  8. Near future Plans

  9. Sharing code

  10. JVM server/interoperability

  11. Java interoperability: upcoming • All new Java APIs: seamless interop • JEP 359: Records (Preview) • JEP 384: Records (Second Preview) • JEP 360: Sealed Classes (Preview)

  12. Driving forces

  13. Driving forces: what to focus on? Community Comm. with Slack & Forums YouTrack KEEP big users

  14. YouTrack vs KEEP • KEEP design documents • Worked out and prototyped • KEEP issues corrections • Problems, ideals, proposals YouTrack #{language design} https://kotl.in/issue

  15. YouTrack: language design 1.1 1.2 1.3 1.4

  16. Distant future Speculative, we are looking for feedback

  17. The most voted request now

  18. KT-11968: Statically accessible extensions All Kotlin extensions are resolved statically

  19. KT-11968: Statically accessible extensions 3 rd -party type val Intent.Companion. SCHEME_SMS : String get() = "sms" Companion type Code with receiver What are you trying to achieve?

  20. KT-11968: Statically accessible extensions val Intent.Companion. SCHEME_SMS : String get() = "sms" What are you trying to achieve? Intent. SCHEME_SMS

  21. Similar/related problem object Delegates { fun <T : Any> notNull(): ... // other declarations } Why object is used here? What are you trying to achieve?

  22. Similar/related problem object Delegates { fun <T : Any> notNull(): ... // other declarations } What are you trying to achieve? Delegates.notNull()

  23. What is object? object Delegates { fun <T : Any> notNull(): ... // other declarations } •Instance val x = Delegates •Type x is Delegates • Namespace Delegates.notNull()

  24. What is object? object Delegates { fun <T : Any> notNull(): ... // other declarations } •Instance val x = Delegates Library maintenance burden •Type x is Delegates • Namespace Delegates.notNull()

  25. What if you could declare just a namespace? object Delegates { fun <T : Any> notNull(): ... // other declarations } • Namespace Delegates.notNull()

  26. What if you could declare just a namespace? namespace Delegates { fun <T : Any> notNull(): ... // other declarations } • Namespace Delegates.notNull()

  27. Enables: companion namespaces class Example { companion object { private val SOME_CONST = … } }

  28. Enables: companion namespaces class Example { namespace { private val SOME_CONST = … } }

  29. Enables: namespaces extensions val Intent.Companion. SCHEME_SMS : String get() = "sms"

  30. Enables: namespaces extensions val namespace<Intent>. SCHEME_SMS : String get() = "sms" Code without receiver What we wanted! Intent. SCHEME_SMS

  31. Multiple receivers

  32. Member extensions class View { fun Float.dp() = this * resources.displayMetrics.density } View Float

  33. KT-10468: Multiple receivers fun (View, Float).dp() = this * resources.displayMetrics.density

  34. KT-10468: Multiple receivers fun View.Float.dp() = …

  35. KT-10468: Multiple receivers fun Float.dp(implicit view: View) = …

  36. Syntactic analogy with (view) { 42f. dp () }

  37. Syntactic analogy with <View> fun Float.dp() = this * resources.displayMetrics.density

  38. Take it further inline fun <T> withTransaction(block: () -> T): T { val tx = beginTransaction () return try { block() } finally { tx.commit() } }

  39. Take it further inline fun <T> withTransaction(block: () -> T): T { val tx = beginTransaction () return try { block() } finally { tx.commit() } }

  40. Take it further inline fun <T> withTransaction(block: () -> T): T { val tx = beginTransaction () return try { block() } finally { tx.commit() } }

  41. Take it further inline fun <T> withTransaction(block: () -> T): T { val tx = beginTransaction () return try { block() } finally { tx.commit() } } fun doSomething() { withTransaction { No magic // code } }

  42. Decorators inline decorator fun <T> withTransaction(block: () -> T): T { val tx = beginTransaction () return try { block() } finally { tx.commit() } } fun doSomething() { withTransaction { // code } }

  43. Decorators inline decorator fun <T> withTransaction(block: () -> T): T { val tx = beginTransaction () return try { block() } finally { tx.commit() } } @ withTransaction The best fun doSomething() { of two // code worlds }

  44. Decorators with receivers inline decorator fun <T> Tx.withTransaction(block: () -> T): T { begin () return try { block() } finally { commit() } } @ withTransaction fun doSomething() { // code } Gets additional receiver Tx

  45. Decorators with receivers @ with <View> fun Float.dp() = this * resources.displayMetrics.density Just a standard decorator!

  46. Public/private property types It does not have to be complicated

  47. Minimal design needed

  48. Ternary operator

  49. When to use which • Kotlin has “if” expression if (foo) a else b Hard for existing code • Kotlin consistently uses “?” in the context of nullability foo ?: b Hard for novices, inconsistent • Boolean abuse in APIs Declined Do you write nullable The goal of Kotlin is to or Boolean before ? enable type-safe APIs

  50. Immutability Cross-cutting trend

  51. Mutable data data class State( var lastUpdate: Instant, | Declare var tags: List<String> ) state.lastUpdate = now() state.tags += tag | Update notifyOnChange(state.copy()) | Share

  52. Immutable data data class State( val lastUpdate: Instant, | Declare val tags: List<String> )

  53. Immutable data data class State( val lastUpdate: Instant, | Declare val tags: List<String> ) state = state.copy( lastUpdate = now(), | Update tag = state.tags + tag ) notifyOnChange(state) | Share

  54. Can we have cake and eat it, too? val class State( val lastUpdate: Instant, | Declare val tags: List<String> ) Value-based class No stable identity

  55. Can we have cake and eat it, too? val class State( val lastUpdate: Instant, | Declare val tags: List<String> ) state.lastUpdate = now() state.tags += tag | Update Copying syntax sugar

  56. Can we have cake and eat it, too? val class State( val lastUpdate: Instant, | Declare val tags: List<String> ) state.lastUpdate = now() state.tags += tag | Update notifyOnChange(state) | Share

  57. Experimental inline classes inline class Color(val rgb: Int) Confusing with Valhalla inline

  58. Stable future for experimental inline classes @__TBD__ val class Color(val rgb: Int) No stable identity

  59. Stable future for experimental inline classes Optimize away boxes when possible @__TBD__ val class Color(val rgb: Int) No stable identity

  60. Other contributions to Kotlin features

  61. Compiler Sources FE Plugins Frontend (declare, resolve) BE Plugins Common BE (codegen) JVM LLVM JS

  62. JetPack Compose @Composable fun Greeting(name: String) { Surface(color = Color.Yellow) { Text(text = "Hello $name!") } }

  63. JetPack Compose @Composable fun Greeting(name: String) { Surface(color = Color.Yellow) { Text(text = "Hello $name!") } } A language feature

  64. Differentiable programming @Facebook @Differentiable fun foo(x: Float, y: Float): Float { val a = x * y val b = a + 5f val c = b * b * b return c } Automatic differentiation

  65. Conclusion

  66. Recap • JVM interop commitment • Namespaces and extensions • Multiple receivers • Public/private property types • Ternary operator • Immutability and inline classes • Other contributions

  67. What else we are looking at? • More concise syntax for algebraic types • Data literals (collection literals, tuples, etc) • Even more flexible properties • Better API evolution/maintenance facilities • Constant evaluation/folding • And more!

  68. Thanks! Have a nice Kotlin @relizarov

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend