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

kotlin-mpp-library-tips

2d855b951ff3160c55915821261432f9?s=47 uzzu
February 18, 2019

 kotlin-mpp-library-tips

Cookpad.apk #2 登壇資料 https://cookpad.connpass.com/event/117054/

2d855b951ff3160c55915821261432f9?s=128

uzzu

February 18, 2019
Tweet

Transcript

  1. ,PUMJO.VMUJ1MBUGPSN-JCSBSZ !V[[V

  2. "HFOEB wܦҢ w,PUMJO.11 .VMUJ1MBUGPSN1SPKFDU ͷ֓ཁ wݱঢ় w5*14ू w ࠓ͸େৎ෉͚ͩͲ কདྷతʹେมͦ͏ͩͳͱࢥ͏ࣄ

  3. ܦҢ  w৽نΞϓϦ޲͚ͷೝূΞϓϦ಺՝ۚ౷ׅϥΠϒϥϦ Λ࡞͍ͬͯΔ J04޲͚ ͜ͷล͸5FDI$POGΛָ͓͠Έʹ w"OESPJEͰ͸ೝূ"1*ΫϥΠΞϯτΞϓϦ಺՝ۚ ϥΠϒϥϦΛͦΕͧΕݸผʹ࡞ΓɺͦΕΛར༻ऀଆ Ͱܨ͗͜ΜͰ͍ͨ

  4. ܦҢ  w"OESPJE༻ͷೝূΞϓϦ಺՝ۚ౷ׅϥΠϒϥϦͷधཁ ͕ߴ·ͬͨ wͨͩ"OESPJE༻ʹϥΠϒϥϦ࡞Δࣄ΋Ͱ͖Δ͕
 ΍Ε͹Ͱ͖ͯ͠·͏ͷͰ௅ઓ͕ͳ͍ w ݱ࣌఺Ͱࣾ಺धཁ͸ແ͍͕ ,PUMJO.11ͷࢼݧӡ༻΋ ݉Ͷͯ΍ͬͯΈΔࣄʹ

  5. ؆୯ͳ֓ཁ wl&YQFSJNFOUBMGFBUVSFJO,PUMJOBOEz w1MBUGPSNؒͰίʔυΛڞ༗͢Δ +7. "OESPJE  +BWB4DSJQU J04 -JOVY 8JOEPXT

    .BD FUDʜ  wϓϥοτϑΥʔϜඇґଘͳίʔυ͸DPNNPOQSPKFDU
 ґଘίʔυ͸QMBUGPSNQSPKFDUʹॻ͍͍ͯ͘
  6. Kotlin Source Codes Kotlin / JVM Kotlin / Native Kotlin

    / JS JVM Android Executable Dynamic Library iOS Node.js Browser JS Server app Desktop app etc… Android app iOS(arm32, arm64, emulator x86_64) MacOS(x86_64) Android(arm32, arm64) Linux(x86_64, arm32, MIPS, MIPS little endian) WebAssembly(wasm32) Windows(mingw x86_64) Frontend Web app Server app etc…
  7. Kotlin Source Codes Kotlin / JVM Kotlin / Native Kotlin

    / JS JVM Android Executable Dynamic Library iOS Node.js Browser JS java.util.concurrent.* Handler pthread etc… Promise Coroutines - ඇಉظॲཧ -> abstraction by CoroutineContext GCD
  8. Kotlin Source Codes Kotlin / JVM Kotlin / Native Kotlin

    / JS JVM Android Executable Dynamic Library iOS Node.js Browser JS nghttp2 libcurl etc… Fetch API ktor-client - HTTPClient -> abstraction by HTTPClientEngine NSURLRequest etc… apache Jetty etc… okhttp etc… request node-fetch etc..
  9. None
  10. .VMUJ,PUMJO.VMUJ1MBUGPSN1SPKFDU ݴ͍͍͚ͨͩ

  11. 5FDIOPMPHZ4UBDL w(SBEMF ,PUMJOʙ ݱࡏ͸  wLPUMJOTUEMJC LPUMJOYDPSPVUJOFTDPSF  LPUMJOYTFSJBMJ[BUJPO LUPSDMJFOU

    wLPUMJOUFTU LPUMJOYDPSPVUJOFTUFTU LUPSDMJFOU NPDL NPDLL BTTFSUL LUMJOU wޙ͸QMBUGPSNʹ߹Θͤͯ0L)UUQ౳
  12. ͔͜͜Β5*14ू

  13. (SBEMF1SPKFDU4USVDUVSF wͦ΋ͦ΋Ͳ͏͠Α͏໰୊ w·Ͱ͸,PUMJO%4-ະαϙʔτͩͬͨ w͔ΒͷQSPKFDUTUSVDUVSFͰ΍͍ͬͯͬͨͱ ͖ͷকདྷతͳϏϧυεΫϦϓτͷϝϯς͕ਏͦ͏ʜ

  14. (SBEMF1SPKFDU4USVDUVSF ➔ܥͷࠒͷQSPKFDUTUSVDUVSFΛ౿ऻ

  15. (SBEMF1SPKFDU4USVDUVSF https://github.com/uzzu/kotlin-mpp-boilerplate

  16. (SBEMF1SPKFDU4USVDUVSF ➔ܥͷࠒͷQSPKFDUTUSVDUVSFΛ౿ऻ ɹBOESPJEϏϧυݻ༗ͷόάʹҾ͔͔ͬΔࣄ΋ͳ͍ ɹͷͰศར͚ͩͬͨͲɺطʹमਖ਼͞Ε͍ͯΔ͠ ɹEFQSFDBUFEʹͳͬͨΒ΍ΊΑ͏͔ͳͱ͍͏ؾ࣋ͪ

  17. *%&4FUUJOHT *%&্ͰͷVOJUUFTU࣮ߦʹࠔͬͨΒ

  18. LUPSDMJFOU wLPUMJOSFqFDUґଘ
 όΠφϦαΠζ͕େ͖͘ͳͬͯ͠·͏ʜ ɹ➔ݱঢ়ख෇͔ͣɻ࣏͍ͨ͠ʜ

  19. LUPSDMJFOUPLIUUQ wϥΠϒϥϦ͸,PUMJO.11Ͱ࡞ͬͯΔ͚Ͳ
 ΞϓϦ͸,PUMJO.11Ͱ͸࡞͍ͬͯͳ͍
 ී௨ͷ"OESPJEΞϓϦ  w"OESPJEͷੈքͰ͸ 3FUSPpU "QPMMP 3FBDU/BUJWF FUDʜͱ΋


    ܨ͍͗ͨधཁ͕͋Δ w0L)UUQ$MJFOUͷΠϯελϯεΛڞ༗͍ͨ͠
  20. LUPSDMJFOUPLIUUQ wLUPSDMJFOUPLIUUQͰ͸ෆՄ ɹ➔0L)UUQ$MJFOU&OHJOFΛࣗ࡞ͯ͠
 ɹɹLUPSDMJFOUքͱ"OESPJEքͰ
 ɹɹ0L)UUQ$MJFOUΛڞ༗

  21. LPUMJOYTFSJBMJ[BUJPO w(SBEMF1MVHJOͰͷ4FSJBMJ[FS%FTFSJBMJ[FSੜ੒ػೳ
 Λ࢖Θͳ͍ͱ͍͚ͳ͍ఔن໛͕େ͖͘ͳ͍
 BOOPUBUJPOQSPDFTTJOH͠ͳͯ͘ࡁΉͳΒͨ͘͠ͳ͍ ɹ➔+TPO0CKFDUMJLFͳػೳ΋͋ΔͷͰͦΕΛ࢖͏
 ɹɹ(SBEMF1MVHJO͸BQQMZෆཁʹ͍ͯ͠Δ
 ɹɹৄࡉ͸https://uzzu.github.io/post/kotlin-json-serialization-mini.html

  22. $PSPVUJOFT wͳΜ͔ͩΜͩͰ.VUFYΛΑ͘࢖͏
 ೝূपΓ͸ฒྻʹ૸ΒΕͯ΋ࠔΔ
 ͔ͭQPTUQPOFʹ΋ͨ͘͠ͳ͍
 ݺͼग़͠͸ճͰɺฒྻʹݺ͹Εͨશͯͷ࣮ߦίϯς Ωετʹฦ٫͍ͨ͠
 ͭ·ΓQVCMJTI SFGDPVOU WJB3Y ͍ͨ͠

  23. $PSPVUJOFT https://github.com/uzzu/kortex

  24. $PSPVUJOFT class CallCount(val value: Int) { override fun equals(other: Any?)

    = this === other } var callCount = 0 suspend fun increment(): CallCount { ++callCount delay(10) return CallCount(callCount) } ྫ ϝιουίʔϧ͞Εͨճ਺Λฦ٫͢Δ͚ͩͷؔ਺
  25. $PSPVUJOFT @Test fun basicWithHot() = runBlocking(hotInvocation()) { val times =

    3 val results = mutableListOf<CallCount>() val jobs = mutableListOf<Job>() repeat(times) { i -> val job = launch { runCatching { withContext(Dispatchers.IO) { withHot("hot") { increment() } } } .onSuccess { results.add(it) } .onFailure { fail("[$i] Exception occurred: $it") } } jobs.add(job) } jobs.forEach { it.join() } assertAll { assertThat(results.size).isEqualTo(times) // શͯͷ࣮ߦContextʹincrement()ͷ݁Ռ͕ฦ٫͞ΕΔ assertThat(results.distinct().size).isEqualTo(1) // ಉҰΦϒδΣΫτ͕ฦ٫͞ΕΔ assertThat(results.distinct()[0].value).isEqualTo(1) // increment()ͷݺग़ճ਺͸1ճ } }
  26. $PSPVUJOFT wৄࡉ͸
 https://uzzu.github.io/post/hot-coroutines.html

  27. 5FTUJOH wجຊతʹDPNNPOʹॻ͘ wDPNNPOʹॻ͍͓ͯ͘ͱɺ֤1MBUGPSNͷVOJU UFTU࣮ߦ࣌ʹ·ͱΊͯVOJUUFTU͕࣮ߦ͞ΕΔ

  28. 5FTUJOH$PSPVUJOFT wSVO#MPDLJOH͸KWNͷΈఏڙ͞Ε͍ͯΔ
 DPNNPOʹςετॻ͖͍ͨ wݱঢ়͸UFTUJOGSBͳTVCQSPKFDUΛ࡞ͬͯSVO#MPDLJOHΛ
 FYQFDUBDUVBMͷܗʹ͍ͯ͠Δ KTͳΒQSPNJTF NPDIBͰ 
 ۩ମతͳίʔυ͸https://gist.github.com/uzzu/58cb8bb12c17605017edd01b8498915a 

    w,PUMJOͳ͍͠$PSPVUJOFT-JCSBSZ্Ͱ
 ରԠ͕ೖΔ༧ఆʜͱࢥ͍ͬͯΔ͚ͲJTTVFḷ͍ͬͯ͘ͱ
 ΋ͬͱ͔͔Γͦ͏ͳؾ͕͢Δʜhttps://youtrack.jetbrains.com/issue/KT-19813
  29. ͜͜·Ͱ5*14

  30. কདྷతʹେมͦ͏ͩͱࢥ͏ࣄ w,PUMJO/BUJWFͷςετ
 .PDLL΋"TTFSUL΋ݱঢ়/BUJWFඇରԠͳͷͰ
 ଴ͪঢ়ଶ

  31. কདྷతʹେมͦ͏ͩͱࢥ͏ࣄ w,PUMJO/BUJWFͷ$*؀ڥ
 J04޲͚ͷςετ͸࣮ߦՄೳܗࣜͰు͍ͯɺYDSVOͯ͠Ϩ ϙʔτूܭ͍ͯ͠ΔJ04Ϗϧυ؀ڥ͕͍Δ
 ଞͷBSDIJUFDUVSF΋ಉ༷
 $*؀ڥͱςετϨϙʔτूܭͲ͏͢Δ QMBUGPSNຖʹ QJQFMJOFԽͯ͠΍ΔΜͩͱࢥ͏ 
 ΋ͪΖΜ/BUJWF͸J04͚ͩͰ͸ͳ͍ͷͰҎԼུ


  32. কདྷతʹେมͦ͏ͩͱࢥ͏ࣄ wͨ͘͞Μ͋ΔͷͰ͓࿩͠·͠ΐ͏ʂ