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

良いコードを書くためにやってみてること3つ.pdf

 良いコードを書くためにやってみてること3つ.pdf

Keisuke kiuchi

October 31, 2018
Tweet

More Decks by Keisuke kiuchi

Other Decks in Programming

Transcript

  1. ྑ͍ίʔυΛॻͨ͘Ίʹ
    ΍ͬͯΈͯΔ͜ͱͭ
    LJVDIJLFJTVLF
    4IJCVZBBQL

    View full-size slide

  2. ໦಺ܒี
    w ৬ۀɿ:ͷ"OESPJEΤϯδχΞ݉ҭࣇύύ
    w झຯͰ࡞ͬͨϞϊɿʮΒ͘ͰΜ "QQ
    ʯɺ

    ʮ$MFBO"SDIJUFDUVSF5FNQMBUF'PS,PUMJO 044
    ʯ
    w Ϟοτʔɿ໌೔ͷࣗ෼ʹ༏͍͠ίʔυΛॻ͘
    w 4/4

    5XJUUFS!GFJ@LPNF

    (JUIVC!LJVDIJLFJTVLF

    2JJUB!L@LFJTVLF

    View full-size slide

  3. ࠷ۙͷΞΫςΟϏςΟ

    View full-size slide

  4. ࠓճͷൃද͸
    كʹΑ͋͘Δ໰୊Λ
    ׂͱΑ͋͘Δख๏Ͱղܾ͠Α͏ͥ
    ͱ͍͏γϯϓϧͳ࿩

    View full-size slide

  5. ΞδΣϯμ
    wҙຯͱ੍໿Λදݱ͠Α͏
    wແΛදݱ͠Α͏
    wϨϏϡʔ؍఺ΛγΣΞ͠Α͏

    View full-size slide

  6. ҙຯͱ੍໿Λදݱ͠Α͏

    View full-size slide

  7. ಥવͰ͕࣭͢໰Ͱ͢
    WBMQIPOF/VN4USJOH
    ͱ͍͏ม਺ΛݟͨΒͲΜͳ஋Λ

    ૝૾͠·͔͢ʁ

    View full-size slide

  8. ࣍ͷ࣭໰
    WBMUFMFQIPOF/VN4USJOH
    ͳΒͲ͏͍͏஋Ͱ͠ΐ͏

    View full-size slide

  9. ࣅͯΔ͚ͲผͷҙຯΛ࣋ͭม਺
    w QIPOF/VNl9999::::
    w UFMFQIPOF/VNlUFM9999::::z
    ʮΒ͘ͰΜʯͷΞϓϦΑΓҰ෦վѱͯ͠ൈਮ

    View full-size slide

  10. EBUBΫϥεJOJUؔ਺Ͱ

    ҙຯͱ੍໿Λදݱ͠Α͏

    View full-size slide

  11. UFMFQIPOF/VNCFSJT
    data class TelephoneNumber(val number: String) {
    init {
    if (!number.startsWith(SCHEME)) {
    throw IllegalArgumentException(“error“)
    } else if (number.substring(SCHEME.length)
    .contains(Regex(“.*[^0-9#¥+¥*() -]+.*"))) {
    throw IllegalArgumentException(“error”)
    }
    }
    companion object {
    const val SCHEME = "tel:"
    }
    }
    4$)&.&͔Β

    ࢝·ͬͯΔ͜ͱ
    ಛఆͷਖ਼نදݱΛ

    ຬͨ͢͜ͱ

    View full-size slide

  12. QIPOF/VNCFSJT
    class PhoneNumber(val number: String) {
    init {
    if (number.startsWith(TelephoneNumber.SCHEME)) {
    throw IllegalArgumentException(“error")
    } else if ((number.contains(Regex(".*[^0-9#¥+¥*() -]+.*")))) {
    throw IllegalArgumentException(“error")
    }
    }
    }
    4$)&.&͔Β࢝·ͬͯ

    ͍ͳ͍͜ͱ
    ಛఆͷਖ਼نදݱΛ

    ຬͨ͢͜ͱ

    View full-size slide

  13. ิ଍JOMJOF$MBTT PSEBUB$MBTT
    w *OMJOFDMBTT ,PUMJOWFSd

    w JOJUϝιουΛ࣋ͯͳ͍ͷͰɺܕ੍໿ͷΈͰे෼ͷ৔߹
    ʹར༻
    w EBUBDMBTT
    w JOJUϝιουΛ࣋ͯΔͰɺܕ੍໿ϩδΧϧͳ੍໿Λ΋
    ͍ͨͤͨ৔߹ʹར༻
    ˞͋͘·Ͱ๻ݸਓͷߟ͑ํͰ͢

    View full-size slide

  14. ແΛදݱ͠Α͏

    View full-size slide

  15. ࣍ͷ໰୊
    ͋Δ-JTU͔Β৚݅ʹ߹கͨ͠

    ཁૉΛऔΓग़ؔ͢਺Λ࡞Γ͍ͨ

    View full-size slide

  16. val contactList = List()
    fun findSameNumberContact(phoneNumber: PhoneNumber):Contact? {
    return contactList.find { it.getPhoneNumber() == phoneNumber }
    }
    ۭͷ-JTU͚ͩͲΩχγφΠσ

    View full-size slide

  17. val contactList = List()
    fun findSameNumberContact(phoneNumber: PhoneNumber):Contact? {
    return contactList.find { it.getPhoneNumber() == phoneNumber }
    }
    Μʁ

    View full-size slide

  18. ແΛදݱ͠Α͏

    View full-size slide

  19. val contactList = List()
    fun findSameNumberContact(phoneNumber: PhoneNumber):Contact {
    return contactList.find { it.phoneNumber == phoneNumber } ?:
    Contact.NONE
    }
    data class Contact(val displayName: String, val contactId: String, val
    phoneNumber: PhoneNumber) {
    companion object {
    val NONE = Contact("", "", PhoneNumber(""))
    }
    }
    dddddddddddddddddddddddddddddddddddddddddddddddddddd

    View full-size slide

  20. /PO/VMMͰແΛදݱʂ

    ˞ͨͩ͠ɺ/VMMͷ··ʹͨ͠΄͏͕ྑ͍৔߹΋͋ΔͷͰ༻๏༻ྔΛकͬͯ࢖͍·͠ΐ͏

    View full-size slide

  21. ิ଍/VMMBCMF PSແΛදݱ
    w ແΛදݱˠ/VMMʹͳΔ͜ͱ͕ਖ਼ৗܥͷൣғ಺ͷ৔߹ྫ֎ॲཧ͕ෆ
    ཁʹͳΔ৔߹
    w ྫ&EJU5FYUʹϢʔβʔ͕ೖྗͨ͠ి࿩൪߸ʹϚον͢Δి࿩൪߸Λ
    pOEͰݟ͚ͭɺి࿩൪߸Λදࣔ͢Δ ݟ͔ͭΒͳ͍ͳΒۭจࣈ

    w /VMMͷ··ˠ/VMMʹͳΔ͜ͱ͕ຊདྷ͋Γ͑ͳ͍৔߹
    w ྫి࿩ாҰཡͰνΣοΫΛೖΕͨ൪߸͚ͩΛpOEͰݟ͚ͭΔ
    ˞͋͘·Ͱ๻ݸਓͷߟ͑ํͰ͢

    View full-size slide

  22. ϨϏϡʔ؍఺ΛγΣΞ͠Α͏

    View full-size slide

  23. ๭೔ɺ͋Δ13ΛϨϏϡʔ
    ͍ͯͨ࣌͠ͷ͜ͱ

    View full-size slide

  24. ࢦఠͨ͠΄͏͕͍͍

    Օॴ͕ଟ͗͢Δ

    View full-size slide

  25. ࢦఠ͠ͳ͍Θ͚ʹ΋͍͔ͳ͍͕ɺ
    શ෦ࢦఠ͢Δͷ΋͠ΜͲ͍

    View full-size slide

  26. ͳͷͰɺָΛͭͭ͠
    νʔϜٕज़ྗͷ޲্ʹܨ͕Δํ๏
    Λ΍ͬͯΈͨ

    View full-size slide

  27. ձٞࣨΛ઎ڌͯ͠

    ϞϒϓϩతϨϏϡʔձΛ࣮ࢪ

    View full-size slide

  28. ϞϒϓϩతϨϏϡʔ
    w ࢀՃऀɿ"OESPJE&OHਓɺJ04&OHਓ
    w ୊ࡐɿྫͷ13 ,PUMJO

    w ΍ͬͨ͜ͱɿ

    ࢦఠՕॴΛͲΜͲΜϗϫΠτϘʔυʹॻ͖ग़͢

    Ͳ͏௚ͨ͠΄͏͕͍͍͔ɺΛٞ࿦͢Δ

    ࢦఠΛ൓ө ͔͚ͨͬͨ͠Ͳ࣌ؒͷ౎߹্࣮ݱͤͣ

    View full-size slide

  29. ϞϒϓϩతϨϏϡʔ
    ˞ࣾ֎ൿͳͷͰϞβΠΫॲཧͯ͠·͢

    View full-size slide

  30. ΍ͬͯΈͨײ৮
    w վΊͯݟͯΈΔͱʮ͜ͷ࣮૷ԿΛҙਤͯ͠ΔΜͩ ʯͬͯͷ͕

    ग़ͯ͘Δ
    w ࢦఠ͞ΕΕ͹౰ͨΓલͱࢥ͑Δ΋ͷ͕ଟ͍
    w ม਺໊ؔ਺໊ͷ໋໊ͷେ੾͞Λ࠶ೝࣝͨ͠
    w ,PUMJOʹ׳Εͯͳ͍ਓ͕ॻ͘ͱ7BS͕ଟ͘ͳΔ

    View full-size slide

  31. ϨϏϡʔ؍఺ΛγΣΞͯ͠ɺ

    νʔϜΈΜͳ͕ཧղͰ͖Δ

    ࣮૷Λ৺͕͚Α͏

    View full-size slide

  32. ·ͱΊ
    wࣅͨҙຯΛ͚࣋ͭͲҟͳΔม਺

    ˠҙຯͱ੍໿Λදݱ͠Α͏
    wOVMMBCMFΛແ͘͢ํ๏

    ˠແΛදݱ͠Α͏
    wνʔϜͷٕज़ྗ޲্΋݉Ͷͯۮʹ͸

    ϨϏϡʔ؍఺ΛγΣΞ͠Α͏

    View full-size slide

  33. ͓ΘΓͰͬ͢ʂ

    View full-size slide