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

Joyful user foundation restructuring with Ruby

Joyful user foundation restructuring with Ruby

RubyWorld Conference 2017 での講演資料です。

MOROHASHI Kyosuke

November 01, 2017
Tweet

More Decks by MOROHASHI Kyosuke

Other Decks in Programming

Transcript

  1. RubyʹΑΔ
    ͨͷ͍͠Ϣʔβʔج൫࠶ߏங
    RubyWorld Conference 2017
    2017-11-01
    ॾڮګհ @moro

    View full-size slide

  2. ‣ (ࣸਅ)
    ղফͰ͖ͨෆ҆

    View full-size slide


  3. Kyosuke MOROHASHI
    moro moro

    View full-size slide


  4. http://techlife.cookpad.com/entry/2017/04/06/172601

    View full-size slide

  5. RubyʹΑΔ
    ͨͷ͍͠Ϣʔβʔج൫࠶ߏங

    View full-size slide

  6. RubyʹΑΔ
    ͨͷ͍͠Ϣʔβʔج൫࠶ߏங

    View full-size slide

  7. ‣ ❌ ͓΋͠Ζ͓͔͍͠
    ‣ ⭕ ͍͖͍͖ͱલ޲͖ʹऔΓ૊ΊΔ
    ʮͨͷ͍͠ʯ

    View full-size slide


  8. And there's business value in fun - after
    all motivation is a major factor in
    programmer productivity.

    ͦΕ͔Βɺʮָ͠͞ʯʹ΋ϏδωεՁ஋͕͋Γ·͢ŠŠ݁ہɺϞνϕʔγϣϯ
    ͕ͦ͜ϓϩάϥϚͷੜ࢈ੑΛࠨӈ͢ΔͷͰ͢ɻ
    https://martinfowler.com/bliki/DynamicTyping.html 

    ( http://bliki-ja.github.io/DynamicTyping/ )

    View full-size slide


  9. ΘΕΘΕ͸ػցͰ͸ͳ͍ͷͰɺ΍Γ͍ͨͱࢥ͏ͱ͖
    ʹɺԿ͔Λୡ੒Ͱ͖ΔΜͰ͢ɻԿ͔Λୡ੒͢Δʹ͸ɺ
    ಥ͖ಈ͔͢಺ͳΔྗ͕ඞཁͰ͢ɻͦΕ͸Ϟνϕʔγϣ
    ϯʹΑͬͯݱΕΔΜͰ͢Ͷɻ ུ
    ϞνϕʔγϣϯΛ
    সͬͯ͸͍͚ͳ͍ɻ
    「なんでRubyなんか作った!? 迷惑だ!」に対するMatzの答え


    http://el.jibun.atmarkit.co.jp/rails/2012/10/ruby-matz-7080.html

    View full-size slide


  10. ͭ·Γʮ͜Μͳ͜ͱΛݴͬͨΒνʔϜϝΠτ͔Βഅࣛʹ͞
    Εͳ͍ͩΖ͏͔ʯɺ͋Δ͍͸ʮϦʔμʔ͔ΒࣤΒΕͳ͍ͩ
    Ζ͏͔ʯͱ͍ͬͨෆ҆ΛɺνʔϜͷϝϯόʔ͔Β෷১͢Δɻ
    ৺ཧֶͷઐ໳༻ޠͰ͸ʮ৺ཧత҆શੑʢQTZDIPMPHJDBM
    TBGFUZʣʯͱݺ͹ΕΔ҆Β͔ͳงғؾΛνʔϜ಺ʹҭΊΔ
    ͔Ͳ͏͔͕ɺ੒ޭͷ伴ͳͷͩͱ͍͏ɻ
    グーグルが突きとめた!社員の「生産性」を高める唯一の方法はこうだ

    --プロジェクト・アリストテレスの全貌


    http://gendai.ismedia.jp/articles/-/48137

    View full-size slide


  11. ‣ ਓʑΛ࠷ߴʹً͔ͤΔ
    ‣ ߴ଎ʹ࣮ݧֶश͢Δ
    ‣ ܧଓతʹՁ஋Λಧ͚Δ
    ‣ ҆શΛඞਢ৚݅ʹ͢Δ
    http://modernagile.org/

    View full-size slide

  12. RubyʹΑΔ
    ͨͷ͍͠Ϣʔβʔج൫࠶ߏங

    View full-size slide

  13. RubyʹΑΔ
    ͨͷ͍͠Ϣʔβʔج൫࠶ߏங

    View full-size slide

  14. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide

  15. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide


  16. http://techlife.cookpad.com/entry/2017/04/06/172601

    View full-size slide

  17. ‣ 10೥લ
    ‣ rails generate scaffold users

    email:string password_digest:string
    ‣ ݱࡏ
    ‣ ͜Ε·Ͱ࢖ͬͯ͘Ε͍ͯΔϢʔβʔ͞Μʹ໎࿭Λ͔͚ͳ͍Α͏
    ஫ҙΛ͸Β͍ͭͭɺϏδωεχʔζͰ͏·Εͨଟछଟ༷ͳ֓೦
    ΍σʔλߏ଄Λ੔ཧͯ͠ɺࠓޙͷαʔϏεల։ͷج൫ͱͳΔɻ
    ؆୯ͳ໰୊͸͋·Γ࢒͍ͬͯͳ͍

    View full-size slide

  18. ‣ ݄࣍ར༻ऀ਺ɿ໿6000ສਓ
    ‣ ϓϨϛΞϜձһ਺ɿ190ສਓҎ্
    ‣ ͜ͷํͨͪʹ໎࿭Λ͔͚ͳ͍͜ͱΛେલఏͱ͠ɺ

    ֓೦Λ੔ཧͯ͠ɺ࣮૷΋γϯϓϧʹ͍ͯ͘͠ɻ
    ؆୯ͳ໰୊͸͋·Γ࢒͍ͬͯͳ͍

    ˞਺ࣈ͸೥݄຤࣌఺

    View full-size slide

  19. The Recipe for
    the World’s Largest
    Rails Monolith
    Akira Matsuda
    https://speakerdeck.com/a_matsuda/the-recipe-for-the-worlds-largest-rails-monolith

    View full-size slide

  20. ҙࣝͯͨ͠ͷ͍ͨ͘͠͠

    View full-size slide


  21. 3VCZ͸ʮͨͷ͠͞ʯΛୈҰͷ໨ඪʹͨ͠ੈքॳͷϓ
    ϩάϥϛϯάݴޠͰ͢ɻ
    — Rubyアプリケーションプログラミング 「1.3 Rubyの哲学」

    View full-size slide

  22. ‣ ੲ͸৽ਐؾӶͷWebϑϨʔϜϫʔΫͩͬͨɻ
    ‣ ޿͘࢖ΘΕͨ݁Ռɺ͍·͸Ѫ଀ͱ΋ʹूΊΔɻ
    Rails 10೥࢙

    View full-size slide


  23. http://techlife.cookpad.com/entry/2017/04/06/172601

    View full-size slide

  24. ‣ จࣈ௨ΓͷʮϨΨγʔʯ= Ҩ࢈
    ‣ ࢲͨͪͷϏδωε͸ɺ͜ͷίʔυ͕͓ۚΛՔ͍Ͱ͘
    Ε͍ͯΔ͔Βͦ͜Ͱ͖͍ͯΔɻ
    ϨΨγʔίʔυ

    View full-size slide


  25. Regardless of what we discover, we understand and truly
    believe that everyone did the best job they could, given
    what they knew at the time, their skills and abilities, the
    resources available, and the situation at hand.
    ͜ͷձͰ͸ɺϓϩδΣΫτͷશһ͕ஔ͔Εͨঢ়گԼͰϕετΛਚͨ͘͠ɺͱ͍
    ͏͜ͱΛٙͬͯ͸ͳΒͳ͍ ฏು༁

    http://www.retrospectives.com/pages/retroPrimeDirective.html

    View full-size slide

  26. ‣ Ruby Ͱனͷ࢓ࣄ͕Ͱ͖ΔΑ͏ʹͳͬͨɻ
    ‣ ͦΕࣗମ͕ɺࢲͨͪʹͱͬͯ͸ͱͯ΋ҒେͳҨ࢈ɻ
    ‣ ͪΌΜͱɺΞοϓσʔτΛ͍ͯ͘͠ɻ
    Rails 10೥࢙

    View full-size slide


  27. b6TFBMMUIFXJTFBOELOPXMFEHFZPVIBWFPG
    ZPVSPXO 4BN`
    ʮ͓લ͕ࣗ෼Ͱ͍࣋ͬͯΔஐܙ΍஌ࣝΛ͋ΔݶΓ࢖ͬͯ͝
    ΒΜΑɺαϜɺʯ
    — 指輪物語「王の帰還」

    View full-size slide

  28. ‣ Fat Controller, Fat Model …
    ‣ Trailblazer ΍ Hanami ͕ྲྀߦ͍ͬͯΔ
    Is Rails dead?

    View full-size slide

  29. ‣ πʔϧ΍ϑϨʔϜϫʔΫΛͨͩద༻͢
    Δ͚ͩͰ͸͏·͍͔͘ͳ͍ɻ
    ‣ എܠʹͳ͍ͬͯͦ͏ͳίϯηϓτΛɺ
    ࣗ෼ͨͪͰͪΌΜͱࢼͯ͠ΈΑ͏ɻ
    ͜ͷ10೥ͷֶͼ:

    View full-size slide


  30. αʔϏε૚ͱͯ͠ͷ Form Object ΛΑ͘ߟ͑ͯΈΔ

    View full-size slide

  31. ‣ ςετՄೳͳʮϞσϧ૚ʯ͸༗༻ɻ
    ‣ ʮϓϨθϯςʔγϣϯͱυϝΠϯͷ෼཭ʯͬͯ΍ͭ
    ‣ ίϯτϩʔϥ͔Β͸ৗʹ who ͱ when ͕౉͞ΕΔɻ
    ‣ ActiveSupport::CurrentAttributes ͳΔ΄Ͳɻ
    ‣ ͩΜͩΜʮϑΥʔϜʯ͡Όͳ͍͜ͱ΋෼͔͖ͬͯͨɻ
    ‣ αʔϏεΛʮೖΕࢠʯʹ͍ͨ͜͠ͱ΋͋Δɻ
    αʔϏε૚ͱͯ͠ͷ Form Object

    View full-size slide


  32. Value ObjectΛൃݟ͢Δ

    View full-size slide

  33. ‣ ొ࿥தͷσʔλ͸ ʮ validate: false ͳϢʔβʔʯͰ͸

    ͳ͍ɻ
    ‣ ొ࿥ͦΕࣗମ΋ҰͭͷେࣄͳػೳͰ͋Δɻ
    ‣ Registration ͱ͍͏֓೦Λൃݟͨ͠ɻ
    ‣ ಉ࣌ʹɺొ࿥ޙʹͪΌΜͱݩͷίϯςΩετʹ໭͢ͷ΋

    ͱͯ΋େࣄͱ͍͏͜ͱ΋ɺֶΜͩɻ
    ͜Ε·ͰͷϏδωε͔Β΋ֶͿ

    View full-size slide

  34. resources :email_registrations, only: %i(show new create) do
    collection do
    get :thanks
    end
    resource :user, controller: :cookpad_users,

    only: %i(show new create), module: :email_registrations
    end
    end
    ‣ &ϝʔϧͰͷϢʔβʔొ࿥ email_registrations
    ࣗମΛϦιʔεͱͯ͠ѻ͏ɻ
    ‣ ͔ͦ͜ΒผϦιʔεͱͯ͠Ϣʔβʔ(cookpad_users)Λ࡞Δɻ

    View full-size slide

  35. ίʔυΛॻ͘ͷ͸

    ͨͷ͍͠

    View full-size slide

  36. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide


  37. b6TFBMMUIFXJTFBOELOPXMFEHFZPVIBWFPG
    ZPVSPXO 4BN`
    ʮ͓લ͕ࣗ෼Ͱ͍࣋ͬͯΔஐܙ΍஌ࣝΛ͋ΔݶΓ࢖ͬͯ͝
    ΒΜΑɺαϜɺʯ
    — 指輪物語「王の帰還」

    View full-size slide

  38. ‣ ;Γ͔͑Γ
    ‣ ݟੵΓͱܭըͮ͘Γ
    ͍ΖΜͳϓϥΫςΟε͕͋Δ͚Ͳɺͪΐͬͱͣͭࢼͨ͠:

    View full-size slide

  39. ‣ ;Γ͔͑Γ
    ‣ ͜Ε·ͰʹԿΛ͔ͨ͠
    ‣ ݟੵΓͱܭըͮ͘Γ
    ‣ ͜Ε͔ΒԿΛ͢Δ͔
    ͍ΖΜͳϓϥΫςΟε͕͋Δ͚Ͳɺͪΐͬͱͣͭࢼͨ͠:

    View full-size slide


  40. ‣ ຖि n ϙΠϯτਐΜͰ͍Δͷ͸Θ͔ͬͨɻ͕ɺ
    ʮ͍ͭͰ͖Δʯ͔͕ݟ͑ͮΒ͔ͬͨɻ
    ‣ ࣮ࡍʹॻ͍ͯΈͨΒɺײ͕֮දݱͰ͖ͯͨɻ

    View full-size slide


  41. ‣ ࣾ಺ͷϓϥΫςΟεΛ༌ೖͨ͠ɻ
    ‣ υϝΠϯΤΩεύʔτʹ͞Θͬͯ΋Β͏ɻ
    ‣ େখ༷ʑͷؾ͍ͮͨ͜ͱΛͲΜͲΜ௚͢ɻ

    View full-size slide


  42. Χϯόϯʹ5SZΛషΔ

    View full-size slide


  43. ‣ TryΛ͍ͭ΋໨ʹ͢ΔΑ͏ʹɺషͬͨɻ
    ‣ ͜Ε͸ະମݧͩͬͨΑ͏ͳɻ

    View full-size slide


  44. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠

    View full-size slide

  45. ‣ ʮ͜Ε·ͰʯʹֶΜͰ
    ‣ RailsҰൠ΍ΞϓϦέʔγϣϯίʔυͷۤ࿑
    ‣ ػೳͷ࢖ΘΕํ
    ‣ ʮ͜Ε͔ΒʯΛߟ͑Δ
    ‣ ͪΐͬͱͣͭʮΑ͍ʯઃܭΛ͢Δ
    ‣ ඞཁͳΒٕज़తෛ࠴ΛआΓೖΕΔ
    ࣅ͍ͯΔ

    View full-size slide

  46. ‣ ʮ͜Ε·ͰʯʹֶΜͰ
    ‣ ͜Ε·ͰͷΠςϨʔγϣϯͰͷνʔϜͷਐΊํɻ
    ‣ ࡞Ζ͏ͱͨ͠ػೳͰ΄Μͱ͏ʹඞཁͩͬͨ΋ͷɻ
    ‣ ʮ͜Ε͔ΒʯΛߟ͑Δ
    ‣ Try
    ‣ ͜Ε·ͰΛ౿·͑ͨݟੵΓͱܭըͮ͘Γɻ
    ࣅ͍ͯΔ

    View full-size slide

  47. ࣗݾ૬ࣅੑ͕͋Δ

    View full-size slide

  48. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide

  49. ʮ஌͍ͬͯͨʯ͜ͱ

    View full-size slide


  50. ͕ͩɺߴΈʹ౸ୡ͢Δ͜ͱ͕໨తͰ͋Ε͹ɺιϑτ
    ΢ΣΞ։ൃ͸ʮϓϩάϥϚʔͱͦͷଞେ੎ʯͰ੒ཱ
    ͢Δ΋ͷͰ͸ͳ͍ɻͦΕ͕ɺաڈ೥ؒͰࢲֶ͕Μ
    ͩ͜ͱͩɻ
    — エクストリーム・プログラミング 「第25章 結論」

    View full-size slide


  51. 5IFSFTBEJ⒎FSFODFCFUXFFO
    LOPXJOHUIFQBUIBOEXBMLJOHUIFQBUI
    ಓΛ஌Δ͜ͱͱา͖ͩ͢͜ͱ͸ҧ͏
    — Morpheus; Matrix

    View full-size slide


  52. 91ͷՁ஋͸ɺϏδωεͷੈքͰ࣮ફ͢΂͖΋ͷͩɻ
    շదʹ฻ΒͤΔੜ׆ΛૹΔ͚ͩͰͳ͘ɺؔ܎ऀશһ
    ͕͓ޓ͍ʹϦεϖΫτͨ͠ਓؒؔ܎ʹΑͬͯɺ৽͠
    ͍ಇ͖ํΛ։ൃ͢ΔͷͰ͋Δɻ ུ
    ૑଄తʹ͍͖͍
    ͖ͱಇ͘ͷͰ͋Δɻ
    — エクストリーム・プログラミング 「第25章 結論」

    View full-size slide

  53. ‣ ͔ͭͯ͸ਖ਼͔ͬͨ͠લఏ (ϝʔϧΞυϨε͕͋ΔɺͳͲ)
    ͕ඞཁҎ্ʹ

    ޿ൣʹద༻͞Ε͍ͯΔɻ
    ‣ ͔ͭͯ͸ʮϝʔϧΞυϨεΛೖྗͯ͠Ϣʔβʔొ࿥ʯΛલఏͱ͍ͯͨ͠ɻ
    ‣ ϝʔϧΞυϨεೖྗΛল͍ͯɺ༗ྉձһͱͯ͠࢖͍͍ͨͱݴͬͯ͘ΕΔ

    Ϣʔβʔ͞Μ΋ग़͖ͯͨɻ
    ‣ ʮΞϓϦΛΠϯετʔϧͯ͘͠ΕͨʯΒϢʔβʔͱѻ͏࢓૊Έ͕͍ΔͷͰ͸ɻ
    ࣗ෼ͨͪͷϏδωεͷϢʔβʔঢ়ଶΛֶशͰ͖͖ͯͨ

    View full-size slide

  54. ‣ αʔϏε։ൃͷ֤ॴͰѻ͍ͮΒ͘ͳ͍ͬͯΔɻ
    ‣ ίϛϡχέʔγϣϯܥͷػೳͰܾࡁखஈΛҙࣝ͠ͳ͍ͱ͍͚ͳ͍ɺͳͲɻ
    ‣ اը΍αϙʔτ΋೉͚͠Ε͹ɺ࣮૷্ͷམͱ݀͠ʹͳΔ͜ͱ΋͋Δɻ
    ‣ ৽͘͠ೖࣾͨ͠ਓ͕ཧղ͢Δͷ΋೉͍͠ɻ
    σʔλঢ়ଶ͕೉͍͠

    View full-size slide


  55. νʔϜ͕ҙࣝతʹ౒ྗ͢Ε͹ɺυϝΠϯϞσϧ͸ͦ
    ͷڞ௨ݴޠͷج൫ͱͳΕΔ͠ɺͦͷҰํͰɺνʔϜ
    ͷίϛϡχέʔγϣϯΛιϑτ΢ΣΞͷ࣮૷ͱ݁ͼ
    ͚ͭΔ͜ͱ΋Ͱ͖Δɻ
    ドメイン駆動設計 「第2章 コミュニケーションと言語の使い方」

    View full-size slide

  56. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide


  57. ͦͷϓϩηεͷͳ͔Ͱɺ։ൃऀͱͯ͠࠷ળΛਚ͘͢
    ͜ͱͩɻϏδωεͷͨΊʹͳΔ༏ΕͨίʔυΛॻ͘
    ͜ͱͩɻ
    — エクストリーム・プログラミング 「第1章 XPとは何か」

    View full-size slide

  58. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide

  59. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide


  60. http://techlife.cookpad.com/entry/2017/04/06/172601

    View full-size slide

  61. ‣ ݄࣍ར༻ऀ਺ɿ໿6000ສਓ
    ‣ ϓϨϛΞϜձһ਺ɿ190ສਓҎ্
    ‣ ͜ͷํͨͪʹ໎࿭Λ͔͚ͳ͍͜ͱΛେલఏͱ͠ɺ

    ֓೦Λ੔ཧͯ͠ɺ࣮૷΋γϯϓϧʹ͍ͯ͘͠ɻ
    ؆୯ͳ໰୊͸͋·Γ࢒͍ͬͯͳ͍

    ˞਺ࣈ͸೥݄຤࣌఺

    View full-size slide

  62. ‣ ٕज़తෛ࠴ΛआΓೖΕͳ͕ΒਐΊΔ
    ‣ Ұ࣌తʹDBͷಉςʔϒϧ΁ෳ਺ΞϓϦέʔγϣϯ͔Β
    write͢Δͱ͔
    ‣ ࠓճ΋ͦͷதͰϕετΛਚ͘͢
    ‣ ػೳͷείʔϓΛ෼͚ͯͪΐͬͱͣͭग़͢ɻ
    ‣ ม਺ͷείʔϓ΋෼͚ΔɺςετՄೳʹ͢Δ… etc
    ࣍ͷʮϨΨγʔʯΛ͍ͭͬͯ͘Δͷ͔΋…

    View full-size slide


  63. 5IFSFTBEJ⒎FSFODFCFUXFFO
    LOPXJOHUIFQBUIBOEXBMLJOHUIFQBUI
    ಓΛ஌Δ͜ͱͱา͖ͩ͢͜ͱ͸ҧ͏
    — Morpheus; Matrix

    View full-size slide

  64. ҙࣝͯͨ͠ͷ͍ͨ͘͠͠

    View full-size slide


  65. ͦΕ͔Βɺʮָ͠͞ʯʹ΋

    ϏδωεՁ஋͕͋Γ·͢
    http://bliki-ja.github.io/DynamicTyping/

    View full-size slide

  66. ίʔυΛॻ͘ͷ͕ͨͷ͍͠
    νʔϜͰ։ൃ͢Δͷ͕ͨͷ͍͠
    νʔϜͱνʔϜͷ֎ͷਓͱ
    ΈΜͳͰαʔϏεΛಧ͚Δͷ͕ͨͷ͍͠

    View full-size slide