リファクタリングチャンスを探せ

4edb44c4292fa5bd1cbe463d0e80ecbd?s=47 Kaoru Hotate
November 27, 2019

 リファクタリングチャンスを探せ

Classi Rails Night #1 2019/11/27 登壇資料
https://connpass.com/event/152405/

4edb44c4292fa5bd1cbe463d0e80ecbd?s=128

Kaoru Hotate

November 27, 2019
Tweet

Transcript

  1. ϦϑΝΫλϦϯάνϟϯεΛ୳ͤʂ ,BPSV)PUBUF!QVSVOLBPSV $SBTTJ3BJMT/JHIU DMBTTJ@SBJMT@OJHIU 1

  2. อཱ֜ ,BPSV)PUBUF  5XJUUFS!QVSVOLBPSV ϝυϐΞͱ͍͏ձࣾͷ ΤϯδχΞͰ͢ 3VCZྺ೥͘Β͍ ΤϯδχΞྺ೥໨ ࣗݾ঺հ 2

  3. ࠓ೔͸ϦϑΝΫλϦϯάͷ࿩Λ͠·͢ʂ 3

  4. ϦϑΝΫλϦϯάͷ࿩ͷલʹɾɾɾ ࠷ۙͷ೰Έࣄʢ૟আʣΛ࿩͠·͢ 4

  5. 5

  6. ‣ झຯɾޘָͷਓ΋͍Δ ੒௕ͷͨΊʹ΍Δਓ΋͍Δ ΍Β͞Εͯ΍Δਓ΋͍Δ ݟͯݟ͵ৼΓΛ͢Δਓ΋͍Δ ‣ ϦϑΝΫλϦϯά΋ ΍Γ͍ͨਓɾզຫͰ͖ͳ͍ਓ͕΍Δʁ ‣ ༷ʑͳਓ͕͍ΔதͰɺϦϑΝΫλϦϯάΛ

    ૊৫ϨϕϧͰߦ͏ͷ͸͔ͳΓ೉ͦ͠͏ ϦϑΝΫλϦϯά΋Ұॹʁ 6
  7. ‣ ࠓ೔͸ɺϦϑΝΫλϦϯάΛ૊৫Ͱߦ͏ࡍͷ ಈػ෇͚ͱࢦ਑ʹয఺Λ౰ͯͯ࿩͠·͢ ‣ ʮͳͥʯ΍ʮͲ͏΍ͬͯʯͰ͸ͳ͘ɺ ʮԿΛʯϦϑΝΫλϦϯά͢Δ͔ʹ͍ͭͯ࿩͠·͢ ‣ ࣮ફ͍ͯ͠Δํ͸࠶֬ೝͰ͖Δ৔ʹͳΕ͹ͱࢥ͍·͢ ࠓ೔ͷ͓͸ͳ͠ 7

  8. 1BSU ΤϯδχΞνʔϜ಺Ͱͷ ϦϑΝΫλϦϯάͷϞνϕʔγϣϯΛ্͛Δ 8

  9. ϦϑΝΫλϦϯάΛ΍Δཧ༝ͷେ෦෼͸ɺҎԼͷͭͰ͢ ‣ ʮ໘നͦ͏ʂʯ ྑ͍ઃܭΛҙࣝ͢ΔͷͰɺ੒௕ʹͭͳ͕Δ ‣ ʮզຫͰ͖ͳ͍ʂʯ ྑ͘ͳ͍ίʔυΛ๾໓ͯ͠ɺਫ਼ਆతॆ଍ײΛಘΔ ଞͷਓʹݟΒΕͨ͘ͳ͍ίʔυΛͬͦ͜Γྑ͓ͯ͘͘͠  ϦϑΝΫλϦϯά͕໨తʹͳΓ͕ͪɾɾɾ

    ϦϑΝΫλϦϯάΛ๻͕΍Δཧ༝ 9
  10. ϦϑΝΫλϦϯά͚ͩͷ࣌ؒΛͱΔ͜ͱͰ ʮྑ͍ઃܭʯΛҙࣝͯ͠ίʔυΛॻ͘Α͏ʹͳΔ ϦϑΝΫλϦϯά͸੒௕ʹͭͳ͕Δ 10 ϦϑΝΫλϦϯά͕ಘҙʹͳΔͱɺʢதུʣѱ͍ίʔυΛॻ͘ͷΛ΍Ίɺ ѱ͍׳शʹै͏ͷΛ΍ΊɺϓϨϑΝΫλϦϯάΛ࢝ΊΔͷͩɻʢதུʣ ίʔυͷϦϑΝΫλϦϯά͸ɺίʔυΛॻ͘ͱ͖ʹͯ͠͸͍͚ͳ͍͜ͱɺ ୅ΘΓʹ͢΂͖͜ͱΛֶͿ্Ͱ࠷଎ͷํ๏ͷͭͳͷͩɻ %BWJE4DPUU#FSOTUFJOஶʮϨΨγʔίʔυ͔Βͷ୤٫ʯΑΓ

  11. ྑ͍ઃܭΛ࣮ײ͢Δ࢓૊Έ͕ඞཁ 11 ‣ ڠྗ͠߹͏ ‣ ϖΞϓϩɾϞϒϓϩ ‣ ٕज़ސ໰ ‣ ϧʔϧʹଇΔ

    ‣ 40-*%ݪଇ ‣ ˓˓ύλʔϯ
  12. ‣ 'BU.PEFMͷղফύλʔϯΛ ͭͷࣄྫʹ෼͚ͯ঺հ͍ͯ͠·͢ IUUQTTQFBLFSEFDLDPNIPUBUFLBPSVGBUNPEFMOJEVJDIVTVSVUVGBMTFSJIVBLVUBSJOHVQBUBO 'BU.PEFMͷղফύλʔϯ 12

  13. ‣ ϦϑΝΫλϦϯά͸୹ظతʹ͓ۚΛੜΈग़ͮ͠Β͍΋ͷ ‣ ΍Γͨͯ͘΋ඇΤϯδχΞ͔Βཧղ͕ಘΒΕͳ͍ ݁Ռ΍Ε͍ͯͳ͍ਓ͕ଟ͍ͷͰ͸ʁ ࣮ࡍ͸ɾɾɾ 13

  14. 1BSU ඇΤϯδχΞʹ΋ ϦϑΝΫλϦϯάΛཧղͯ͠΋Β͏ 14

  15. ͚ͩ͜͜ͷ࿩Ͱ͕͢ɺ ؆୯ͳํ๏Λݟ͚ͭ·ͨ͠ 15

  16. ΠϯύΫτͷ͋Δʮ΍Β͔͠ʯΛ͢Ε͹0,  ˞੹೚͸औΓ·ͤΜ 16

  17. ‣ ϦϑΝΫλϦϯάͱ͍͏޻਺͸ɺ ୹ظతʹपΓʹධՁ͞ΕͮΒ͍ ཧղΛಘͮΒ͍ ‣ ධՁɾཧղΛಘΔͨΊʹ͸ɺ਺ࣈ͕ඞཁ ‣ ඇΤϯδχΞͷཧղΛಘΔͨΊʹ͸ ఆྔతʹ੒ՌΛग़ͤΔՕॴ͔Β ϦϑΝΫλϦϯά͠·͠ΐ͏

    ϦϑΝΫλϦϯάͷ੒ՌΛ໌֬ʹ͠Α͏ 17
  18. ‣ ϨεϙϯελΠϜ ‣ ςετͷ࣮ߦ଎౓ ‣ ίʔυͷ඼࣭ ‣ $PEF$MJNJBUF ‣ SVCZDSJUJD

    ‣ ίʔυͷՄಡੑ ‣ $POUSPMMFSͷߦ਺ ‣ 3VCPDPQͷEJTBCMF਺ ϦϑΝΫλϦϯάͷఆྔతͳ੒Ռ 18
  19. ‣ /FX3FMJD΍4LZMJHIUͰ ϨεϙϯελΠϜ͕஗͍ॲཧΛௐࠪ ‣ मਖ਼ྫ ‣ / Λແ͘͢ ‣ ൃߦ͞ΕΔΫΤϦΛνϡʔχϯά͢Δ

    ‣ ඇಉظʹͰ͖Δॲཧ͸ඇಉظʹ͢Δ ‣ ஗͍ॲཧΛݺͼग़͢ճ਺ΛݮΒ͢ ‣ SFEJTNFNDBDIFE ϦϑΝΫλϦϯάͷ,1*ྫʢϨεϙϯελΠϜʣ 19
  20. ‣ ѹ౗తʹ஗͍ͷ͸ɺKTUSVFͳ&&ͷςετ ‣ KTଆͷϩδοΫΛKFTUͳͲͷKTςετʹدͤΔ ‣ $POUSPMMFSͷϩδοΫΛ.PEFMଆʹدͤΔ ‣ ͨ·ʹམͪΔςετͷ࡟আ ϦϑΝΫλϦϯάͷ,1*ྫʢςετͷ࣮ߦ଎౓ʣ 20

  21. ‣ ෳ਺Օॴͷڞ௨ϩδοΫʢίϐϖʣΛݮΒ͢ ‣ ෳࡶͳ࣮૷ΛݮΒ͢ मਖ਼ྫ ‣ $PEF$MJNBUFͷධՁΛ্͛Δ ‣ SVCZDSJUJDͷධՁΛ্͛Δ ϦϑΝΫλϦϯάͷ,1*ྫʢίʔυͷ඼࣭ΛߴΊΔʣ

    21
  22. https://codeclimate.com/ ‣ Φʔϓϯιʔε͸ແྉ ‣ ೔ؒͷτϥΠΞϧظؒ͋Γ ͦͷ͋ͱ͸༗ྉ ‣ ࣌ؒʹ༨༟͕͋Ε͹ը໘ݟͤΔ $PEF$MJNBUF 22

  23. https://github.com/whitesmith/rubycritic ‣ ࣌ؒʹ༨༟͕͋Ε͹ը໘ݟͤΔ SVCZDSJUJD 23

  24. ‣ ʮඞཁʹഭΒΕΔલʹʯՄಡੑΛߴΊΔमਖ਼Λߦ͏ ‣ ඇΤϯδχΞ΁ͷཧղ͸ඞཁ मਖ਼ྫ ‣ $POUSPMMFSͷߦ਺ΛݮΒ͢ ‣ 3VCPDPQͷEJTBCMF਺ΛݮΒ͢ ‣

    .PEFMͷॲཧΛผΫϥεʹҕৡ͢Δ ϦϑΝΫλϦϯάͷ,1*ྫʢՄಡੑΛߴΊΔʣ 24
  25. ‣ ϦϑΝΫλϦϯά͸ΤϯδχΞͱͯ͠ͷ੒௕ʹͭͳ͕Δ ‣ ΤϯδχΞ͕ࣗൃతʹϦϑΝΫλϦϯά͢ΔͨΊʹ͸ɺ ੒௕Λ࣮ײͰ͖Δ࢓૊Έ͕ඞཁ ‣ ඇΤϯδχΞʹϦϑΝΫλϦϯά޻਺Λ ཧղͯ͠΋Β͏ͨΊʹ͸ɺ ਺஋Ͱ੒ՌΛใࠂͰ͖ΔϦϑΝΫλϦϯά͕ඞཁ ·ͱΊ

    25
  26. ࢀߟจݙ 26 ‣ ϨΨγʔίʔυ͔Βͷ୤٫ ʕιϑτ΢ΣΞͷण໋ΛԆ͹͠ Ձ஋ΛߴΊΔͭͷϓϥΫςΟε %BWJE4DPUU#FSOTUFJOஶ

  27. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ 27