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

黒歴史リポジトリを使ったリファクタリング勉強法のススメ

fuqda
August 13, 2019

 黒歴史リポジトリを使ったリファクタリング勉強法のススメ

Otemachi.rb#20の発表資料です。
リファクタリングを利用した勉強方法の話をします。

fuqda

August 13, 2019
Tweet

More Decks by fuqda

Other Decks in Programming

Transcript

  1. ࠇྺ࢙ϦϙδτϦΛ
    ࢖ͬͨϦϑΝΫλϦϯά
    ษڧ๏ͷεεϝ
    ɹɹɹɹɹɹɹɹ fuqda(@fuqda90)
    2019.08.14(Wed) Otemachi.rb#20

    View full-size slide

  2. ࣗݾ঺հ

    Tama.rb Organizor

    Work @ STORES.jp, inc.

    RubyͰ!Λ৯΂ΔΑ͏ʹͳΓ2೥໨Ͱ͢
    Twitter : fuqda(@fuqda90)

    Github : Shigeyuki-fukuda
    (JU)VC

    View full-size slide

  3. ௚࣮ۙફͨ݁͠Ռ

    ޮՌ͕͋ͬͨΦεεϝ
    ษڧ๏ͷ࿩"

    View full-size slide

  4. ʲ࣭໰ʳ

    ٕज़ॻಡΜͩޙ
    ࣮ફͯ͠·͔͢ʁ

    View full-size slide

  5. ʲ࣭໰2ʳ

    ಡΜ͚ͩͩͩͱ਎ʹ෇͍͔ͨෆ҆…
    ͱ͍͏͔…๨Ε·ͤΜ͔?
    (ͪͳΈʹ๻͸ͦ͏Ͱ͢#)

    View full-size slide

  6. ؾܰʹຊͰֶΜͩ಺༰Λ

    ࣮ફ͍ͨ͠

    View full-size slide

  7. (࠷ѱյΕͯ΋ྑ͍ΞϓϦͰ$)

    View full-size slide

  8. ͦ͜ͰΦεεϝ͍ͨ͠ʂ

    View full-size slide

  9. ۦ͚ग़͠ͷࠒʹॻ͍ͨίʔυ

    (ࠇྺ࢙ϦϙδτϦ)ͷ
    ϦϑΝΫλϦϯά %✨

    View full-size slide

  10. ୯७ʹϦϑΝΫλϦϯάग़དྷΔ༨஍͕ଟ͍
    →௚͢༨஍͕গͳ͍ͱ࡞ۀͯͯͭ͠·Βͳ͍ͷͰ
    ɹۃ୺ʹ伱ͩΒ͚ͷίʔυΛϘίϘίʹ௚͘͢Β͍͕
    ɹ୊ࡐͱͯ͠ྑ͍
    ษڧΛͨ͠ݱ࣌఺ͱ͢Δલͷࠩ෼͕໌֬
    →Ͳͷ͘Β͍਎ʹ෇͍͍ͯΔ͔ʁΛ஌͕ࣝͳ͔ͬͨࠒ
    ɹͱൺ΂Δ͜ͱͰݱঢ়ͷཧղ౓ͷ೺Ѳʹ໾ཱͪͦ͏

    View full-size slide

  11. ΋ͬͱݴ͏ͱ
    ϖΞϓϩͰ΍ΔͷΛ
    Φεεϝ͍ͨ͠✋

    View full-size slide

  12. ϖΞϓϩͰ΍Δํ͕͍͍ཧ༝
    ࢥߟͷ੔ཧ͕ग़དྷΔ
    →ҰਓͩͱԿͱͳͬͪ͘͜ͷίʔυͷํ͕ྑ͍͔Βͱ
    ɹᐆດʹ͢Δͱ͜ΖΛ૬ख͕͍ΔͱԿނͦͷॻ͖ํ͕
    ɹྑ͍ͷ͔Λઆ໌͢Δඞཁ͕ग़ͯ͘Δʂ
    ɹͦͷͨΊઆ໌ͷաఔͰᐆດͳཧղʹؾ෇͚ͯྑ͍
    →૬खͱࣗ෼ͰΞϓϩʔν͕ҧ͏৔໘͕͋Δ͸ͣͳͷͰ
    ɹͦΕ͕ͦͷ··ֶͼʹͳΔ

    View full-size slide

  13. ࣮ࡍʹ΍͍ͬͯͬͨ͜ͱ

    View full-size slide

  14. Tama.rbͷ˞ࣗݾ঺հ༻ΨνϟΞϓϦͷ

    ϦϑΝΫλϦϯά
    ※Tama.rbؔ܎ऀͷ๭ࢯ͕ۦ͚ग़͠ͷࠒʹ
    ࡞ͬͨΞϓϦΛڐՄΛ΋Βͬͯ௚͢͜ͱʹ…
    ϝϯόʔ
    @fuqda @ken3ypa

    View full-size slide

  15. ʲΞϓϦ֓ཁʳ
    ࣗݾ঺հΨνϟ
    ɾQuestion(࣭໰)
    ɾConjunction(઀ଓࢺ)
    ɾTheme(ςʔϚ)
    ͜ΕΒͷΧςΰϦʔʹ֘౰͢Δొ࿥ϫʔυΛ
    ΨνϟͷΑ͏ʹҾ͍ͯ
    ϥϯμϜͰը໘ʹදࣔ͠
    ͦΕΛݩʹࣗݾ঺հͯ͠΋Β͏ΞϓϦ

    View full-size slide

  16. ϦϑΝΫλϦϯάͷΰʔϧ
    ៉ྷͳίʔυʹ௚͢(ͦΕ͚ͩ͡Όͳ͍)
    ⭕ ۦ͚ग़͔͠Βࠓ·ͰֶΜͩΦϒδΣΫτ
    ࢦ޲ͷΞϨίϨ΍֤छॻ੶ͷֶश಺༰Λ
    Ξ΢τϓοτग़དྷΔ͔ΛϦϑΝΫλϦϯά
    ͷதͰ֬ೝ͢Δ͜ͱ

    View full-size slide

  17. ϦϑΝΫλϦϯά͢Δ
    ্ͰνΣοΫ߲ͨ͠໨

    View full-size slide

  18. ɾ໋໊ͷଥ౰ੑνΣοΫ
    ɹ (Ϋϥε໊ɾϝιου໊ɾΧϥϜ໊etc…)
    ͦͷ໊લͰ఻ΘΔʁ
    ex)ͱ͋ΔϕϯνϟʔاۀͰϗϯτʹ͋ͬͨා໋໊͍
    class EmailMailer
    →Կʹର͢Δϝʔϧ͕͍ͨ͠Ϋϥεͳͷ͔શ͘఻ΘΒΜ
    ޿͗͢Δ໋໊͡Όͳ͍ʁ
    ex) Ϋϥε໊ɿGroup, Operation
    →޿໊͍લʹ͸prefix͕ඞཁͦ͏
    γεςϜ্Ϳ͔ͭΔ໊લ͡Όͳ͍ʁ
    ex) ΧϥϜ໊ɿsize, count
    →ͦͷੲ๭ϑΝογϣϯܥαʔϏεͰ෰ͷαΠζΛsizeͱ͍͏
    ΧϥϜͰ؅ཧͨ͠ͱ͜ΖORϚούʔͷ಺෦ͷϝιουͱ
    Ϳ͔ͭͬͯҙਤ͠ͳ͍ڍಈΛͨ͜͠ͱ͕͋ͬͨͦ͏ͳ

    View full-size slide

  19. ɾΫΤϦͷଥ౰ੑνΣοΫ

    View full-size slide

  20. ɾϞσϦϯάͷଥ౰ੑνΣοΫ
    ຊ౰ʹ͜ͷϞσϧඞཁʁ
    →QuestionϞσϧҰͭʹ
    ɹ ActiveRecord::EnumΛੜ΍ͯ͠؅ཧ͢Ε͹
    ɹ Conjunction(઀ଓࢺ)ͱ
    ɹ ThemeϞσϧෆཁͳͷͰ͸ʁ
    ※Πϝʔδ
    enum category: { conjunction: 0, theme: 1 }

    View full-size slide

  21. ɾRailsత/OOPత͔νΣοΫ
    ੹຿͕ద੾ʹ෼ׂ͞ΕͯΔʁ
    →AΫϥε͕BΫϥεͷதͷॲཧΛ஌Γա͗ͯͳ͍͔
    →ԿͰ΋԰ͷαʔϏεΫϥεͱ͔࡞ͬͯͨΒຣࡴ(ࠓճ͸ແ͠)
    ͜ͷ࣮૷ͳ͍ͱμϝʁ
    →ෳ਺ͷϞσϧͰڞ௨ͨ͠ॲཧ͕
    ɹActiveSupport::Concernʹ·ͱΊΒΕ͍͕ͯͨ
    ͦ΋ͦ΋ແବͳϞσϧΛ࡟আͨ͠Β
    ActiveSupport::Concern͍Βͳ͘ͳ͍ʁ^_^;
    ɹ➡ ຣࡴ

    View full-size slide

  22. ɾϦϑΝΫλϦϯάͰग़ͯ͘ΔΞΠσΞ
    ɹͦͷ΋ͷ͕ࠓͷࣗ෼ͷ࣮ྗ
    ɾۀ຿ͩͱେਓͷࣄ৘ͰϦϑΝΫλϦϯάʹ
    ɹͳ͔ͳ͔खΛ෇͚ΒΕͳ͍͔΋ͳͷͰ…
    झຯͷίʔυͰͿͬյ͠ͳ͕ΒֶΜͰ
    ɹۀ຿ίʔυʹ΋൓өग़དྷͨΒྑͦ͞͏✨
    ɾϖΞϓϩɾϞϒϓϩͰࠓճͷΑ͏ͳϦϑΝΫλϦϯάΛ
    ͢Δͱ୯७ʹָ͍͠ & ษڧʹͳΔͷͰ
    ೔ʑͷֶशϚϯωϦଧഁʹ͓ࢼ͋͠Ε

    View full-size slide

  23. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠3
    ͝ਗ਼ௌ

    View full-size slide