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. ໦಺ܒี w ৬ۀɿ:ͷ"OESPJEΤϯδχΞ݉ҭࣇύύ w झຯͰ࡞ͬͨϞϊɿʮΒ͘ͰΜ "QQ ʯɺ
 ʮ$MFBO"SDIJUFDUVSF5FNQMBUF'PS,PUMJO 044 ʯ

    w Ϟοτʔɿ໌೔ͷࣗ෼ʹ༏͍͠ίʔυΛॻ͘ w 4/4
 5XJUUFS!GFJ@LPNF
 (JUIVC!LJVDIJLFJTVLF
 2JJUB!L@LFJTVLF
  2. 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$)&.&͔Β
 ࢝·ͬͯΔ͜ͱ ಛఆͷਖ਼نදݱΛ
 ຬͨ͢͜ͱ
  3. 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$)&.&͔Β࢝·ͬͯ
 ͍ͳ͍͜ͱ ಛఆͷਖ਼نදݱΛ
 ຬͨ͢͜ͱ
  4. ิ଍JOMJOF$MBTT PSEBUB$MBTT w *OMJOFDMBTT ,PUMJOWFSd  w JOJUϝιουΛ࣋ͯͳ͍ͷͰɺܕ੍໿ͷΈͰे෼ͷ৔߹ ʹར༻ w

    EBUBDMBTT w JOJUϝιουΛ࣋ͯΔͰɺܕ੍໿ ϩδΧϧͳ੍໿Λ΋ ͍ͨͤͨ৔߹ʹར༻ ˞͋͘·Ͱ๻ݸਓͷߟ͑ํͰ͢
  5. val contactList = List<Contact>() 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