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

ふつうのひとががんばらずに問題児コードを改善している話

 ふつうのひとががんばらずに問題児コードを改善している話

2021/03/02 ANDPAD TechLive #3 プロダクトの成長と共に歩むRails開発改善の歴史と未来

8847086af047cbf895ab3277b59529fe?s=128

ANDPAD inc

March 03, 2021
Tweet

Transcript

  1. ;ͭ͏ͷͻͱ͕ ͕Μ͹Βͣʹ ໰୊ࣇίʔυΛվળ͍ͯ͠Δ࿩ 2021.03.02. ANDPAD TechLive #3 @makicamel

  2. w!NBLJDBNFM઒ݪສق wɹ w3VCZͱϏʔϧɹɹͱ͓ञ͕޷͖ ࣗݾ঺հ

  3. ANDPADͷίʔυ͸໰୊ࣇἧ͍

  4. ໰୊ࣇྫ

  5. class Users::GreetingsController < Users::ApplicationController before_action :set_greeting before_action :energy_required def set_greeting

    @greeting = current_user.greeting end before_action :depressed_greeting_required, only: [:destroy] def depressed_greeting_required raise UnauthorizedError unless @greeting.depressed? end # νϟοτͰͷΈར༻ include Common::Chats::GreetingsController def greeting_permissions chat_permissions end end ݟ௨͠ͷ ѱ͍Ϋϥε
  6. class Greeting < ApplicationRecord include GreetingRelation # relation include GreetingScope

    # scope # enum include State # ֤greetingͷ࡞੒ include ForActionAccount include ForActionOrder # include ForActionWork include ForActionCustomer # ... end ϞδϡʔϧͰޡຐԽ͞ΕͨϑΝοτΫϥε
  7. class Users::ContactsController < Users::ApplicationController crud_controller Contact, [:new, :create] def new

    # ... end private def scope # ... end end ΦϨΦϨϑϨʔϜϫʔΫ
  8. class Admin::GreetingsController < Admin::ApplicationController AdminRoutes::STRUCTURES.each_pair do |k, v| define_method k

    do # ... end v.each_pair do |kk, vv| define_method "#{kk}_hi" do # ... end define_method “#{kk}_goodbye" do # ... end end end end ϝλϓϩ
  9. ʮ͋ͬͦͷมߋਖ਼͍͠ΜͰ͚͢Ͳ طଘͷڍಈ͕Ͱ͢Ͷ 👼ʯ

  10. ※ ;ͭ͏ʹਆςʔϒϧͱ͔ৗਓʹ͸ཧղ͕ࠔ೉ͳίʔϧόοΫͱ͔΋͋Γ·͢

  11. •ϝϯςίετ͕ߴ͍ •όάɾো֐Λى͜͠΍͍͢ •ௐࠪɾػೳ௥Ճɾमਖ਼ʹ͔͔Δ͕࣌ؒ૝ఆͷ n ഒ๲Ε͕ͪ •ΦϯϘʔσΟϯάίετ͕ߴ͍ •ׂΕ૭ΛੜΉ •ͳΜ͔Πϥοͱ͢Δ ໰୊ࣇ͕ͨͪҾ͖ى͜͢͜ͱ

  12. ;ͭ͏ͷίʔυʹ໭͍ͨ͠

  13. ͱ͜ΖͰͦͷ޻਺͸Ͳ͜ʹ͋ΔΜͰ͔͢ʁ

  14. ʰ)6/5&3º)6/5&3ʱୈר࿩ʮରܾᶆʯ෌ֽٛത

  15. ࢒೦ͳ͕Β೦ೳྗऀͰ͸ͳ͍ͷͰ

  16. ;ͭ͏ͷͻͱ͕ ͕Μ͹Βͣʹ ໰୊ࣇίʔυΛվળ͍ͯ͠Δ࿩

  17. ຊ೔ͷίϯςϯπ •εΫϦϓτԽ͢Δ •͕Μ͹Βͳ͍ •҆શʹ΍Δ •޿ΊΔ ※ ʮΑ͍ઃܭͱ͸ʯʮࣗಈςετͷͳ͍ϓϩδΣΫτͰࣗಈςετΛॻ͘ʯ ͷΑ͏ͳ࿩͸͠·ͤΜ •εΫϦϓτԽ͢Δ •͕Μ͹Βͳ͍

    •҆શʹ΍Δ •޿ΊΔ 🤖
  18. class Users::GreetingsController < Users::ApplicationController before_action :set_greeting before_action :energy_required def set_greeting

    @greeting = current_user.greeting end before_action :depressed_greeting_required, only: [:destroy] def depressed_greeting_required raise UnauthorizedError unless @greeting.depressed? end # νϟοτͰͷΈར༻ include Common::Chats::GreetingsController def greeting_permissions chat_permissions end end ݟ௨͠ͷѱ͍ ίϯτϩʔϥ
  19. class Users::GreetingsController < Users::ApplicationController before_action :set_greeting before_action :energy_required def set_greeting

    @greeting = current_user.greeting end before_action :depressed_greeting_required, only: [:destroy] def depressed_greeting_required raise UnauthorizedError unless @greeting.depressed? end # νϟοτͰͷΈར༻ include Common::Chats::GreetingsController def greeting_permissions chat_permissions end end •ΈͮΒ͍ •ͲΕ͕ΞΫγϣϯʁ •͍ͭͲͷίʔϧόοΫ͕ൃՐ͢Δͷʁ •͜ͷϞδϡʔϧ͸Ұମ…ʁ •chat_permissionsͬͯԿ
  20. εΫϦϓτԽҎલ •ૺ۰͢Δ౓ʹख࡞ۀͰ੔ཧ •ඇΞΫγϣϯͳϝιουΛ private ʹ͢Δ •ίʔϧόοΫ΍ϞδϡʔϧͷincludeΛΫϥε্෦ʹ·ͱΊΔ

  21. εΫϦϓτԽҎલ •ΊΜͲ͍͘͞ •ຖճಉ͜͡ͱ΍ͬͯΔ •εΫϦϓτԽͰ͖ΔͷͰ͸

  22. None
  23. •ϝιουͷهड़ॱ੔ཧ •1 Օॴ͔ΒͷΈݺ͹Ε͍ͯΔϞδϡʔϧͷΠϯϥΠϯԽ •ΦϨΦϨϑϨʔϜϫʔΫͷҾ͖ണ͕͠ ಉ͡มߋΛ·ͱΊͯػցతʹߦ͏ͷͰ
 ϨϏϡʔ͠΍͍͢ͱ͍͏ϝϦοτ΋ εΫϦϓτԽྫ🤖

  24. •ʮಛఆύλʔϯͷจࣈྻΛ࣋ͭϝιουҰཡʯௐࠪ •਺ेʙ਺ඦͷௐࠪ݁Ռͷ GitHub Issue Խ εΫϦϓτԽྫ🤖 ࠶ར༻ੑ͕ߴ͘ϛεɾ࿙Εͳ͘ૣ͍ͷͰ ௐࠪʹ΋΂ΜΓ

  25. ୀ۶ͳ͜ͱ͸3VCZʹ͓Ͷ͕͍͠Α͏4QFBLFS%FDLc!NBLJDBNFM IUUQTTQFBLFSEFDLDPNNBLJDBNFMBVUPNBUFUIFCPSJOHTUB⒎XJUISVCZ εΫϦϓτԽྫ🤖 •ଞͷྫɾ΂ΜΓͳಓ۩ʹ͍ͭͯ͸Ҏલผͷͱ͜ΖͰ͓࿩͠·ͨ͠

  26. ຊ೔ͷίϯςϯπ •εΫϦϓτԽ͢Δ •͕Μ͹Βͳ͍ •҆શʹ΍Δ •޿ΊΔ 🏖

  27. Case 1.

  28. •༻్ෆ໌ͳίϯτϩʔϥ͕Ұఆ਺͋Δ •ফ͠๨Ε͕ओ •ௐࠪɾमਖ਼ޙʹʮ͑ͬ࢖ΘΕͯͳ͍ʯͱͳΔͱ൵͍͠ •ফ͍ͨ͠ •ϩάͰར༻༗ແΛ֬ೝޙʹ͞ΑͳΒ͢Δ ༻్ෆ໌ͳίϯτϩʔϥ

  29. •ϦΫΤετ͕ͳ͍৔߹ •࡟আ •ϦΫΤετ͕͋Δ৔߹ •ଓ౤ •͘͝كʹϦΫΤετ͕͋Δ৔߹ •զʑ͸Ͳ͔͜Βདྷͨͷ͔ ༻్ෆ໌ͳίϯτϩʔϥ 🍎 ⚾

  30. •ಛʹ JavaScript Λհͨ͠ར༻Օॴͷಛఆ͕ࠔ೉ •AngularJS, Vue.js, jQuery ͕ಉϦϙδτϦͰڞଘ •angularjs-rails-resource ͷࣗ༝౓͕ڟѱ •Өڹൣғͷ֬ೝʹ͕͔͔࣌ؒΔ

    •ͲΕ͚ͩௐ΂ͯ΋֬৴͕࣋ͯͳ͍ ༻్ෆ໌ͳίϯτϩʔϥ 'JOF-JOF1SPUPUZQJOHBOHVMBSKTSBJMTSFTPVSDF IUUQTHJUIVCDPN'JOF-JOF1SPUPUZQJOHBOHVMBSKTSBJMTSFTPVSDF
  31. None
  32. •before •͕Μ͹ͬͯ grep ͢Δͷ͸େมͩ͠࿙ΕΔ •after •ʮͭ·Γ஌Γ͍ͨͷͬͯϦϑΝϥͩΑͶʁʯ •Rails ʹฉ͚͹ָͰਖ਼֬ ͕Μ͹Βͳ͍

  33. Case 2.

  34. •Rails ͷϝιουͷར༻ঢ়گΛௐ΂͍ͨ •ಛఆΫϥε͕Ϩγʔόͷ࣌ •ಛఆͷύϥϝʔλΛड͚औΔ࣌ •grep ͸ແཧήʔ •Ruby ͸ࣗ༝ͳͷͰ ϝιουͷར༻ঢ়گΛ஌Γ͍ͨ

  35. None
  36. •before •͕Μ͹ͬͯ grep ͢Δͷ͸ർΕΔ͠࿙ΕΔ •after •ϝιουΛΦʔόʔϥΠυ •ಛఆ৚݅Ͱݺ͹ΕͨΒ Bugsnag ʹ௨஌ͯ͠ super

    ͢Δ ※ ςετͰ΋͋Δఔ౓ݕ஌Ͱ͖Δ͚Ͳ ɹςετ͕ͳ͍ͱ͜ΖͰݺ͹ΕΔՄೳੑ΋͋ΔͷͰຊ൪ಋೖ ͕Μ͹Βͳ͍
  37. ͕Μ͹Βͳ͍ ֎෦APIར༻࣌͸ඇಉظʹ͢Δɾ
 ΤϥʔϋϯυϦϯά౳๨Εͣʹ…!!
 ʢো֐ى͜͠·ͨ͠ʣ

  38. ຊ೔ͷίϯςϯπ •εΫϦϓτԽ͢Δ •͕Μ͹Βͳ͍ •҆શʹ΍Δ •޿ΊΔ ⛑

  39. ɹϦϦʔε͠·ͨ͠ʂ ɹԿ΍Βಈ࡞͕͓͔͍͠ΜͰ͕͢…ʁ ɹো֐ͩʂ੾Γ໭͠·͢ʂ ɹྟ࣌ϦϦʔεऴΘΓ·ͨ͠… Α͋͘Δޫܠ ɹ;Γ͔͑ΓɾϙετϞʔςϜऴΘΓ·ͨ͠… ɹ࠶मਖ਼͠·͢…

  40. •όάΛੜΈ΍͍͢ίʔυ •Өڹൣғ͕ಡΊͳ͍ •ෳࡶͳཁ͕݅ͦͷ··࢓༷ʹͳ͓ͬͯΓɺ࢓༷͕ෳࡶ •ޡͬͨطଘͷڍಈ͕ਖ਼ͱͯ͠ಈ͍͍ͯΔ •જࡏόάͱ͍͏஍ཕ ো֐ΛੜΈ΍͍͢ঢ়ଶ

  41. •ྟ࣌ϦϦʔε͚ͩͰ൒೔ʢݱঢ়ʣ͔͔Δ ※ ඵͰऴΘΔΑ͏վળத •ௐࠪɾ;Γ͔͑Γɾ࠶ൃ๷ࢭͱͦͷϨϏϡʔͳͲͰ໿ 1 ೔ফ͑Δ •։ൃ෦ͷ৴པΛଛͳ͏ ো֐Λى͜͢ͱ

  42. ো֐Λىͨ͘͜͠ͳ͍ •ҰேҰ༦ʹղܾͰ͖Δ՝୊Ͱ͸ͳ͍ •ো֐Λى͜͠΍͍͢ݱঢ়Ͱ΋҆શʹϦϦʔεͰ͖Δํ๏͕΄͍͠

  43. •ϦϦʔεΛ 2 ஈ֊ʹΘ͚Α͏ ҆શʹϦϦʔεͰ͖Δํ๏

  44. 2 ஈ֊ϦϦʔε class ApplicationController < ActionController::Base private # ... #

    վम࣌ʹ҆શʹมߋΛ͢ΔͨΊͷϝιου # ྫ֎ൃੜ࣌ʹຊ൪؀ڥͰ͸௨஌Λૹͬͯݕূ͢ΔͨΊʹར༻͢Δ # 1ʙ2िؒఔ౓༷ࢠΛݟͯ໰୊͕ͳ͚Ε͹ϒϩοΫΛ֎͢ def temporary_ignore_error yield rescue => e if ::Rails.env.production? ::Bugsnag.notify(e) else raise e end end end
  45. •e.g. όϦσʔγϣϯΛมߋ͠ɺྫ֎Λൃੜͤ͞Δमਖ਼ •before 1. ਖ਼͍͠มߋΛ͕ͨ͠ɺݩͷڍಈ͕ؒҧ͓ͬͯΓޡͬͨϦΫΤ ετ͕ૹΒΕ͖ͯͯϢʔβۀ຿ΛࢭΊͨ 😱 2. ͋Δը໘Ͱ͸ਖ਼͍͠มߋΛ͕ͨ͠ɺ༧૝͍ͯ͠ͳ͍ը໘ͰΤ ϯυϙΠϯτ͕ར༻͞Ε͓ͯΓϢʔβۀ຿ΛࢭΊͨ

    😱 2 ஈ֊ϦϦʔε
  46. •e.g. όϦσʔγϣϯΛมߋ͠ɺྫ֎Λൃੜͤ͞Δमਖ਼ •after •ຊ൪Ͱ͸ Bugsnag ʹ௨஌͢Δ͚ͩɺྫ֎Λى͜͞ͳ͍ •ҙਤ͠ͳ͍ϦΫΤετ͕͋ͬͨ৔߹ݕ஌Ͱ͖Δ •ܦա؍࡯ޙɺ࣮ࡍʹྫ֎Λൃੜͤ͞Δ 2 ஈ֊ϦϦʔε

  47. •σϝϦοτ •ίʔυมߋͷ࣮ಋೖ͕஗ΕΔ •2 ஈ֊ϦϦʔε͕ΊΜͲ͏͍͘͞ •ϝϦοτ •҆৺ɾ҆શʹϦϦʔεͰ͖ো֐ΛݮΒͤΔ •ϨϏϡʔෛՙ͕ݮͬͨ 2 ஈ֊ϦϦʔε

  48. •Darklaunch ͱ͍͏࢓૊Έ΋ผͷϝϯό͕࡞ͬͯ͘Εͨ •ձࣾ୯ҐͰػೳΛΦϯɾΦϑ͢Δ •Cookpad ͞Μͷ Chanko ΋༗໊Ͱ͢Ͷ 2 ஈ֊ϦϦʔε DPPLQBEDIBOLP3BQJEMZBOETBGFMZQSPUPUZQJOHZPVSSBJMTBQQMJDBUJPO

    IUUQTHJUIVCDPNDPPLQBEDIBOLP
  49. ຊ೔ͷίϯςϯπ •εΫϦϓτԽ͢Δ •͕Μ͹Βͳ͍ •҆શʹ΍Δ •޿ΊΔ 🗣

  50. •ձࣾಠࣗͷ࢓૊Έ͸ೝ஌ʹ͕͔͔࣌ؒΔ •प஌Λͯ͠΋ɺ৘ใײ౓͸ਓͦΕͧΕ •ʮԿͳͷ͔ʯʮ͍ͭ࢖͑Δͷ͔ʯʮͲ͏΍ͬͯ࢖͏ͷ͔ʯ Λखܰʹ఻͑Δͷ͸೉͍͠ •৽͘͠ࢀըͨ͠ਓ͸΋ͪΖΜ஌Βͳ͍ •΄΅ຖ݄ΤϯδχΞ͕δϣΠϯ͍ͯ͠Δʢײँʣ ࢓૊ΈΛ޿ΊΔ

  51. •ʮϞϒϓϩνʔϜʯΛ݁੒ɺִि 1 ౓ߦ͍ͬͯΔ •͓୊͸ίʔυվળɾύϑΥʔϚϯεվળ etc •νʔϜϝϯό͕୭͔Λ༠ͬͯू·Δӡ༻ •ΦϯϘʔσΟϯάظʹಛʹϫʔΫͦ͠͏ •සग़ΞϯνύλʔϯɺഎܠɺରԠύλʔϯɺಓ۩ͳͲ Ϟϒ /

    ϖΞϓϩ
  52. จষΛॻ͘

  53. •֓ཁ •ίʔυྫɾಋೖͷ࢓ํ •஫ҙࣄ߲ •ۜͷ஄ؙͰ͸ͳ͍ͱ͔ •ܦա؍࡯ޙʹফ͢ͷ͓๨Εͳ͘ͱ͔ •࢓૊Έ จষΛॻ͘ 2ʙ3෼ͰಡΊΔ͘Β͍
 Ͱ͖ΔݶΓ؆ܿʹ

  54. จষΛॻ͘

  55. •୭΋͕໨ʹ͢Δ৔ॴʹ৘ใΛஔ͘ •ςϯϓϨʔτʹ࢓ࣄͯ͠΋Β͏ จষΛॻ͘

  56. ຊ೔ͷίϯςϯπ •εΫϦϓτԽ͢Δ •͕Μ͹Βͳ͍ •҆શʹ΍Δ •޿ΊΔ 🤖 🏖 ⛑ 🗣

  57. ·ͱΊ •࣌ؒΛ࡞Δ •3 ਓʹ͸ͳΕͳ͍͚Ͳɺ࡞ۀ࣌ؒΛ 1/3ʢҎԼʣʹ͸Ͱ͖Δ •εΫϦϓτͱ͔ Rails ͱ͔௨஌ͱ͔ esa ͱ͔ςϯϓϨʔτͱ͔ʹ࢓

    ࣄͯ͠΋Β͏ •ٕज़తʹ೉͍͜͠ͱ͸΍͍ͬͯͳ͍ •;ͭ͏ʹ Ruby / Rails ͷίʔυ͕ॻ͚Ε͹Ͱ͖Δ͜ͱ͹͔Γ •ʮ͕Μ͹Βͳ͍ʯ͜ͱΛ͕Μ͹Δ
  58. •ػೳ։ൃɾमਖ਼͕εϜʔζʹͰ͖ΔΑ͏ʹ •໌Β͔ʹΑ͘ͳ͍΋ͷʹ৮Εଓ͚Δͷ͸Α͘ͳ͍ •ʮطଘ͕ͦ͏ͩ͠ཧ༝΋Θ͔Βͳ͍͔Β฿ͬͨํ͕ྑ͍ͷ͔ͳ…ʯ •ʮͲ͏͋Δ΂͖ͳΜ͚ͩͬʁʯͷٞ࿦͕ੜ·Εʹ͍͘ •ΘΕΘΕ͸ྑ͍ʢमਖ਼͠΍͍͢ʣίʔυΛָ͘͠ॻ͖͍ͨ •Rubyist ͳΜͩ͠ ͳͥίʔυͷվળΛ͢Δͷ͔

  59. )BQQZ$PEJOH

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