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

20210404 Kotlin Tech Talk発表『例外ではなくnullを返すKotlin...

20210404 Kotlin Tech Talk発表『例外ではなくnullを返すKotlinらしいAPIデザイン』

doyaaaaaken

April 05, 2021
Tweet

More Decks by doyaaaaaken

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • ࢓ࣄ • גࣜձࣾsmartround ૑ۀϝϯόʔ / CTO • αʔόαΠυKotlinɾVueJSΛࠓ͸Α͘ॻ͍͍ͯ·͢

    • OSS׆ಈ • kotlin-csvͷ࡞ऀʢ⭐: ໿250ʣ • KtorɾExposedɾkotest౳΁ͷίϯτϦϏϡʔτ • झຯ • ອըɾήʔϜɾϓϩάϥϛϯάɾάϧϝɾςχεɾϘʔυήʔϜɾຑ੃ɾཱྀߦ…etc
  2. ՝୊΁ͷରॲ • ೔෇จࣈྻΛύʔε͢Δutilityؔ਺Λ࡞ͬͨ • fun parseLocalDate(dateStr: String): LocalDate? • ՝୊఺1:

    yyyy-MM-ddܗࣜͷจࣈྻ͔͠ड͚෇͚ͳ͍ 㱺 ෳ਺ͷ೔෇ϑΥʔϚοτΛύʔεՄೳʹɻղܾʂʂ • ՝୊఺2: ྫ֎ͷ৔߹ʹඋ͑try-catchΛॻ͘ඞཁ͕͋Γ৑௕ 㱺 ྫ֎Ͱ͸ͳ͘nullΛฦ͢Α͏ʹɻղܾʂʂ
  3. ίʔυϨϏϡʔ • ࣭໰಺༰ • ࣭໰ɿʰ ྫ֎Ͱ͸ͳ͘nullΛฦ͢Α͏ʹͨ͠ͷ͸ͳͥʁʱ • ݩʑJavaඪ४ϥΠϒϥϦ͕ྫ֎Λฦ͢ͷ͸ཧ༝͕͋ΔͷͰ͸ͳ͍͔ʁ • ճ౴

    1. ྫ֎Λฦ͢ඞવੑ͕ͳ͍ͨΊ 2. nullableʹ͢Δઃܭͷ΄͏͕try-catchΛॻ͔ͣʹࡁΈɺίʔυهड़ྔ͕গͳ͘ͳΔ 3. Kotilnͷඪ४ϥΠϒϥϦͱ͔Λݟͯͯ΋ɺͪ͜Βͷ΄͏͕KotlinͬΆ͍͔Β
  4. ίʔυϨϏϡʔ • ࣭໰಺༰ • ࣭໰ɿʰ ྫ֎Ͱ͸ͳ͘nullΛฦ͢Α͏ʹͨ͠ͷ͸ͳͥʁʱ • ݩʑJavaඪ४ϥΠϒϥϦ͕ྫ֎Λฦ͢ͷ͸ཧ༝͕͋ΔͷͰ͸ͳ͍͔ʁ • ճ౴

    1. ྫ֎Λฦ͢ඞવੑ͕ͳ͍ͨΊ 2. nullableʹ͢Δઃܭͷ΄͏͕try-catchΛॻ͔ͣʹࡁΈɺίʔυهड़ྔ͕গͳ͘ͳΔ 3. Kotilnͷඪ४ϥΠϒϥϦͱ͔Λݟͯͯ΋ɺͪ͜Βͷ΄͏͕KotlinͬΆ͍͔Β ओ؍తͳճ౴ͳͷͰɺ΋͏গ͖ͪ͠ΜͱݴޠԽͯ͠આ໌͍ͨ͠ͱײ͍ͯͨ͡
  5. ༗ࣝऀͷݟղ • JetbrainsͷKotlin։ൃϦʔυͷਓ͕ॻ͍ͨهࣄ͕ෲམͪ͢Δ಺༰ͩͬͨ • Kotlin and Exceptions • ཁ໿ •

    KotlinΒ͍͠APIσβΠϯͱͯ͠͸… 1. ϝιουͷฦΓ஋Λnull΍ઐ༻ܕʹ͢Δ͜ͱͰɺϝιουͷৼΔ෣͍Λදݱ͢΂͖ 2. ྫ֎͸༧ظͤ͵໰୊ൃੜ࣌ʹ౤͛ɺͦͷྫ֎͸ΞϓϦέʔγϣϯͷϧʔτϨϕϧͰHandling͢΂͖ • JavaϥΠϒϥϦ͕ྫ֎Λฦ͢͜ͱ͕ଟ͍ͷ͸ݕࠪྫ֎͕͋Δ͔Β • Kotlinඪ४ϥΠϒϥϦ΋ OrNull ͕͍ͭͨ΋ͷ͕ଟ͍ • ྫɿStringܕͷtoIntOrNull, ListܕͷgetOrNull, firstOrNull …
  6. ͦͷଞɿࢀߟهࣄ঺հ • ࠓճͷ಺༰ͷৄࡉ͸ҎԼهࣄʹ·ͱ·͍ͬͯ·͢ • ʰKotlinΒ͍͠APIσβΠϯʹ͢Δʹ͸ྫ֎Ͱ͸ͳ͘nullΛฦ͢ʱ ※ ଞʹ΋Kotlinؔ࿈ͷTipsܥهࣄΛ৭ʑॻ͍ͯ·͢ • ʰKotlinͷlazyʢ஗Ԇॲཧʣͷ࢓૊ΈΛௐ΂ͯࣗ෼Ͱ؆қʹ࣮૷ͯ͠Έͨʱ •

    ʰKotlinͷΫϥεҕৡͷ࢖͍ॴʱ • ʰKotlinʹ͓͚ΔFactoryϝιουͷ࣮૷ύλʔϯʱ • ʰKotlinͰωετߏ଄ͷDSLΛ࣮૷͢Δํ๏ʱ • ʰܕ҆શʹIDͷܕΛએݴ͢Δ࣮૷ύλʔϯʢKotlinͷ৔߹ʣʱ • ʰKotlinͷSequenceͱListͷڍಈͷҧ͍ʹ͍ͭͯʱ
  7. ձࣾએ఻ • smartroundͰ͸ΤϯδχΞΛ ઈࢍืू͍ͯ͠·͢ʂʂ • ʰελʔτΞοϓɾ౤ࢿՈؒͷσʔλڞ༗ɾ؅ཧ ϓϥοτϑΥʔϜʱΛ։ൃ • ελʔτΞοϓ1500ࣾɾ౤ࢿՈ100͕ࣾొ࿥ •

    αʔόαΠυKotlinɾVue.jsɾAWSΛར༻ • ࣾһ਺10໊ఔͷϑΣʔζͰ͢ ࿩͚ͩฉ͍͍ͨํ΋େ׻ܴͳͷͰWantedlyɾTwitter DM͔Β͓ؾܰʹ͝Ԡื͍ͩ͘͞ʂ ࢀߟ63- w αʔϏε-1ϖʔδ w ٕज़঺հࢿྉʰTNBSUSPVOEΛࢧ͑Δٕज़ʱ w XBOUFEMZ࠾༻ϖʔδ