Travelling Across Asia - Our Journey from Java to Kotlin

Travelling Across Asia - Our Journey from Java to Kotlin

Given at Android Makers FR - Paris, 2018

225a5f32a222d1b8ff2506af8c5a51a1?s=128

Amal Kakaiya

April 23, 2018
Tweet

Transcript

  1. TRAVELLING ACROSS ASIA OUR JOURNEY FROM JAVA TO KOTLIN Amal

    Kakaiya @K4KYA @DeliverooEng
  2. None
  3. DISCLAIMER: COULD TAKE MORE THAN 20 HOURS

  4. Java Kotlin AutoValue/Lombok Data classes Streams support Standard lib functions

    Retrolambda Built in lambda support Butterknife Kotterknife/delegate properties # TravellingAcrossAsia @K4KYA
  5. ADOPTING A NEW LANGUAGE IS A HUGE STEP # TravellingAcrossAsia

    @K4KYA
  6. TESTS ARE AN EASY WAY TO GET STARTED # TravellingAcrossAsia

    @K4KYA
  7. TESTS ARE AN EASY WAY TO GET STARTED BUT NOT

    VERY EXCITING # TravellingAcrossAsia @K4KYA
  8. HOW MUCH COULD WE IMPROVE THE MAIN APP? # TravellingAcrossAsia

    @K4KYA
  9. None
  10. DON’T GO ROGUE! # TravellingAcrossAsia @K4KYA

  11. KOTLIN HOUR THE MEETING YOU ACTUALLY WANT TO GO TO

    # TravellingAcrossAsia @K4KYA
  12. YOU CAN’T START USING A LANGUAGE WITHOUT EVERYBODY KNOWING IT

    # TravellingAcrossAsia @K4KYA
  13. DO WE REALLY WANT TO ADD ANOTHER DEPENDENCY? # TravellingAcrossAsia

    @K4KYA
  14. None
  15. # TravellingAcrossAsia @K4KYA

  16. # TravellingAcrossAsia @K4KYA

  17. FIND YOUR OWN PACE # TravellingAcrossAsia @K4KYA

  18. None
  19. CONVERT ALL THE THINGS!! # TravellingAcrossAsia @K4KYA

  20. IT WASN’T A SMOOTH RIDE # TravellingAcrossAsia @K4KYA

  21. LEARN FROM EACH OTHER # TravellingAcrossAsia @K4KYA

  22. WE REVIEW CODE EVERY DAY # TravellingAcrossAsia @K4KYA

  23. # TravellingAcrossAsia @K4KYA

  24. ANDROID STUDIO IS YOUR FRIEND # TravellingAcrossAsia @K4KYA

  25. private fun mapToIds(items: List<Item>): List<String> { val ids = mutableListOf<String>()

    for (item in items) { ids.add(item.id) } return ids } # TravellingAcrossAsia @K4KYA
  26. private fun mapToIds(items: List<Item>): List<String> { val ids = items.map

    { it.id } return ids } # TravellingAcrossAsia @K4KYA
  27. private fun mapToIds(items: List<Item>): List<String> { return items.map { it.id

    } } # TravellingAcrossAsia @K4KYA
  28. private fun mapToIds(items: List<Item>): List<String> = items.map { it.id }

    # TravellingAcrossAsia @K4KYA
  29. WHAT’S THIS CODE DOING? # TravellingAcrossAsia @K4KYA

  30. private final mapToId(Ljava/util/List;)Ljava/ util/List; L0 LINENUMBER 2 L0 ALOAD 1

    CHECKCAST java/lang/Iterable ASTORE 2 ———————— 75 more lines ———————— # TravellingAcrossAsia @K4KYA
  31. private final List mapToId(List items) { Iterable $receiver$iv = (Iterable)items;

    Collection destination$iv$iv = (Collection)(new ArrayList(CollectionsKt.collectionSizeOrDefault($receiver$ iv, 10))); Iterator var5 = $receiver$iv.iterator(); while(var5.hasNext()) { Object item$iv$iv = var5.next(); Item it = (Item)item$iv$iv; String var12 = it.id; destination$iv$iv.add(var12); } return (List)destination$iv$iv; } # TravellingAcrossAsia @K4KYA
  32. EXPECT THE UNEXPECTED # TravellingAcrossAsia @K4KYA

  33. val extraOptions = items .map { "Item $it" } .takeIf

    { showExtraOptions } # TravellingAcrossAsia @K4KYA
  34. Iterable $receiver$iv = (Iterable)items; Collection $receiver$iv = (Collection)(new ArrayList(CollectionsKt.collectionSizeOrDefault($receiver$iv, 10)));

    Iterator var8 = $receiver$iv.iterator(); while(var8.hasNext()) { Object item$iv$iv = var8.next(); String it = (String)item$iv$iv; String var17 = "Item " + it; $receiver$iv.add(var17); } List var10000 = (List)$receiver$iv; List extraOptions = showExtraOptions ? var10000 : null; # TravellingAcrossAsia @K4KYA
  35. Iterable $receiver$iv = (Iterable)items; Collection $receiver$iv = (Collection)(new ArrayList(CollectionsKt.collectionSizeOrDefault($receiver$iv, 10)));

    Iterator var8 = $receiver$iv.iterator(); while(var8.hasNext()) { Object item$iv$iv = var8.next(); String it = (String)item$iv$iv; String var17 = "Item " + it; $receiver$iv.add(var17); } List var10000 = (List)$receiver$iv; List extraOptions = showExtraOptions ? var10000 : null; # TravellingAcrossAsia @K4KYA
  36. val extraOptions = if (showExtraOptions) items .map { "Item $it"

    } else null # TravellingAcrossAsia @K4KYA
  37. CONVERTING CODE # TravellingAcrossAsia @K4KYA

  38. CONVERTING CODE # TravellingAcrossAsia @K4KYA

  39. CONVERTING CODE # TravellingAcrossAsia @K4KYA

  40. CONVERTING CODE ⌘⌥⇧K Ctrl+Alt+⇧+K # TravellingAcrossAsia @K4KYA

  41. CONVERTING CODE # TravellingAcrossAsia @K4KYA

  42. CONVERTING CODE # TravellingAcrossAsia @K4KYA

  43. CONVERTING CODE # TravellingAcrossAsia @K4KYA

  44. CONVERSION CREEP # TravellingAcrossAsia @K4KYA

  45. NULLPOINTEREXCEPTION # TravellingAcrossAsia @K4KYA

  46. NULLPOINTEREXCEPTION # TravellingAcrossAsia @K4KYA

  47. KOTLINNULLPOINTEREXCEPTION # TravellingAcrossAsia @K4KYA

  48. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) } # TravellingAcrossAsia @K4KYA
  49. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) } # TravellingAcrossAsia @K4KYA
  50. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) } # TravellingAcrossAsia @K4KYA
  51. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) } # TravellingAcrossAsia @K4KYA
  52. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent? -> login(password()) } # TravellingAcrossAsia @K4KYA
  53. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent? -> login(password()) } # TravellingAcrossAsia @K4KYA
  54. CONVERTING CODE class VerifyActivity: BaseActivity<VerifyPresenter>, VerifyScreen { override val message:

    String = getString(R.string.verify_error) # TravellingAcrossAsia @K4KYA
  55. CONVERTING CODE class VerifyActivity: BaseActivity<VerifyPresenter>, VerifyScreen { override val message:

    String get() = getString(R.string.verify_error) # TravellingAcrossAsia @K4KYA
  56. USE VERSION CONTROL EFFECTIVELY # TravellingAcrossAsia @K4KYA

  57. USE VERSION CONTROL EFFECTIVELY AND YOUR TEAM WILL ❤ YOU

    # TravellingAcrossAsia @K4KYA
  58. VERSION HISTORY # TravellingAcrossAsia @K4KYA

  59. VERSION CONTROL CONVERSION AS ONE COMMIT # TravellingAcrossAsia @K4KYA

  60. VERSION CONTROL MERGE CONVERSIONS QUICKLY # TravellingAcrossAsia @K4KYA

  61. VERSION CONTROL # TravellingAcrossAsia @K4KYA

  62. VERSION CONTROL SHARE WHAT YOU LEARNED # TravellingAcrossAsia @K4KYA

  63. SHARE WHAT YOU LEARNED VERSION CONTROL # TravellingAcrossAsia @K4KYA

  64. SHARE WHAT YOU LEARNED VERSION CONTROL # TravellingAcrossAsia @K4KYA

  65. VERSION CONTROL LEAVE IN RETURN TYPES WHEN IT MAKES SENSE

    # TravellingAcrossAsia @K4KYA
  66. VERSION CONTROL private fun showPrompt(confirmed: Boolean) = zip(flipper().confirmDrinkingAgeEnabled(), just(confirmed) {

    enabled, confirmed -> enabled && (!confirmed) } # TravellingAcrossAsia @K4KYA
  67. VERSION CONTROL private fun showPrompt(confirmed: Boolean): Observable<Boolean> = zip(flipper().confirmDrinkingAgeEnabled(), just(confirmed)

    { enabled, confirmed -> enabled && (!confirmed) } # TravellingAcrossAsia @K4KYA
  68. # TravellingAcrossAsia @K4KYA

  69. ANDROIDANNOTATIONS AUTOVALUE BUTTERKNIFE LOMBOK DAGGER CUSTOM ANNOTATION PROCESSOR # TravellingAcrossAsia

    @K4KYA
  70. KAPT KAY - AY - PEE - TEE # TravellingAcrossAsia

    @K4KYA
  71. KAPT VS LOMBOK A TRUE STORY # TravellingAcrossAsia @K4KYA

  72. KAPT VS LOMBOK A TRUE STORY # TravellingAcrossAsia @K4KYA

  73. WHAT WOULD WE CHANGE? # TravellingAcrossAsia @K4KYA

  74. CONVERT UTIL CLASSES EARLY # TravellingAcrossAsia @K4KYA

  75. @file:JvmName(“ViewUtils") @JvmName("showView") fun View.show(visible: Boolean) { visibility = if (visible)

    VISIBLE else GONE } # TravellingAcrossAsia @K4KYA
  76. DO WHAT WORKS FOR YOUR TEAM # TravellingAcrossAsia @K4KYA

  77. None
  78. THANK YOU WE’RE HIRING Amal Kakaiya @K4KYA