Good interface: Command pattern as an example

Good interface: Command pattern as an example

110cd4dcaed019b3bd9809e541afdeb6?s=128

Masafumi Okura

June 08, 2019
Tweet

Transcript

  1. ྑ͍ΠϯλʔϑΣΠεͷ୳ٻ ίϚϯυύλʔϯΛྫʹ େ૔խ࢙ʢ@okuramasafumiʣ ໊ݹ԰Rubyձٞ04―େਢԋܳ৔ 2019-06-08ʢ౔ʣ

  2. ࠓ೔ͷൃද͸࿩୊͕͋ͪͪ͜ʹ ભҠ͍͖ͯ͠·͢ɻ མޠͩͱࢥָͬͯ͠Έͳ͕Β ͓͔͚͖͍ͬͯͯͩ͘͞!

  3. pp self • ໊લɿ΂͢ͱ௾·͞;Έʢେ૔խ࢙ʣ • ॴଐɿϑϦʔϥϯε • ׆ಈ৔ॴɿ౦ژ • ޷͖ͳgemɿPry,

    RSpec • ӡӦͯ͠ΔίϛϡχςΟɿGrow.rb
  4. ໊ݹ԰Rubyձٞ

  5. ໊ݹ԰Rubyձٞ

  6. զʑ͸ͳͥRubyΛ࢖͏ͷ͔

  7. Rubyͷ࿩

  8. զʑ͸ͳͥRubyΛ࢖͏ͷ͔ • ॻ͖΍͍͢ • ʮॻ͖΍͢͞ʯͬͯͳΜͩΖ͏ • ಡΈ΍͍͢ • ʮಡΈ΍͢͞ʯͬͯ(ry •

    Rails
  9. զʑ͕RubyΛ࢖͏ཧ༝

  10. ϓϩάϥϛϯάָ͕͍͠

  11. ͳͥRubyͰϓϩάϥϛϯάΛ͢Δͱ ָ͍͠ͷͩΖ͏͔ʁ

  12. https://www.atmarkit.co.jp/news/ 200907/24/ruby2.html

  13. yuguiɿ ͦΕ͸ɺίϨΫγϣϯ͕͋ͬͯγϟοϑϧ ͍ͨ͠ͱࢥͬͨΒɺshuffleͱॻ͍ͯɺͦΕ Ͱಈ͔ͳ͖Ό͍͚ͳ͍ΜͰ͢Αɻ

  14. ࢥͬͨͱ͓Γʹಈ͘ ʢৗʹಈ͘ͱ͸ݴ͍ͬͯͳ͍ʣ

  15. ͱ͜ΖͰɿ ͳΜͰ͜ͷ࿩Λ͍ͯ͠Δͷ͔

  16. ָ͘͠ϓϩάϥϛϯάͰ͖Δ ྖҬΛ޿͍͛ͨʂ

  17. ϥΠϒϥϦΛॻ͍ͯΈΑ͏ →ॻ͖·ͨ͠

  18. https://github.com/okuramasafumi/ neco

  19. 150ߦͪΐ͍ͷϥΠϒϥϦ

  20. 2ճ΄Ͳॻ͖௚͍ͯ͠Δ

  21. ΠϯλʔϑΣΠεʹೲಘ͕͍͔ͳ͔ͬͨ

  22. ΠϯλʔϑΣΠεʹ͍ͭͯ ͍Ζ͍Ζߟ͑ͨͷͰɺ ͦͷ੒ՌʢʁʣΛڞ༗͍ͨ͠

  23. ͦ΋ͦ΋ɿ ΠϯλʔϑΣΠεͬͯ ͳΜ͚ͩͬʁ

  24. Interface (MacOSͷࣙॻΑΓ) 1. a point where two systems, subjects, organizations,

    etc. meet and interact 2. Computing a device or program enabling a user to communicate with a computer
  25. ΠϯλʔϑΣΠε͸ ίϯϐϡʔλͱͷίϛϡχέʔγϣϯ ͷͱΓํΛܾఆ͢Δ΋ͷ

  26. ΠϯλʔϑΣΠεʹϝιου

  27. ΠϯλʔϑΣΠεʹϝιουγάχνϟ

  28. ʮࢥͬͨͱ͓Γʹಈ͘ʯ

  29. Ruby͸ ΠϯλʔϑΣΠεʢ㲓ϝιουγάχνϟʣ ͕ྑ͍͔Β࢖ΘΕ͍ͯΔ

  30. DSL

  31. ҎԼɺ ʮDSLʯ͸ʮݴޠ಺DSLʯΛࢦ͠·͢

  32. Domain Specific Language

  33. Ruby͕࢖ΘΕΔཧ༝ͷҰͭ

  34. RubyʹΑΔDSLͷ۩ମྫ • ActiveRecordʢRailsܥʣ • RakeʢϏϧυܥʣ • RSpecʢBDDʣ • Puppet΍ChefɺVagrantʢDevOpsܥʣ •

    HomebrewʢύοέʔδϚωʔδϟʣ
  35. ڞ௨఺

  36. DSL͸Կ͔Λఆ͍ٛͯ͠Δ

  37. RubyʹΑΔDSLͷ۩ମྫʢ࠶ܝʣ • ActiveRecordʢRailsܥʣ • RakeʢϏϧυܥʣ • RSpecʢBDDʣ • Puppet΍ChefɺVagrantʢDevOpsܥʣ •

    HomebrewʢύοέʔδϚωʔδϟʣ
  38. RubyʹΑΔDSLͷ۩ମྫʢఆٛྫ෇͖ʣ • ActiveRecordʢσʔλϞσϧͷఆٛʣ • RakeʢϏϧυϓϩηεͷఆٛʣ • RSpecʢ๬·ΕΔৼΔ෣͍ͷఆٛʣ • Puppet΍ChefɺVagrantʢ֤छΠϯϑϥϦιʔεͷఆٛʣ •

    Homebrewʢύοέʔδͷఆٛʣ
  39. ͱ͜ΖͰɿ DSL͸୯ͳΔΫϥεϝιου ʢͷ৔߹͕ଟ͍ʣ

  40. ͭ·Γɿ DSL΋·ͨΠϯλʔϑΣΠε

  41. ͜͜·Ͱͷ·ͱΊ • ΠϯλʔϑΣΠε͕ྑ͍ͱָ͘͠ϓϩάϥϛϯάͰ͖Δ • ΠϯλʔϑΣΠεͱ͸͍͍ͩͨϝιουγάχνϟͷ͜ͱ • ֤ॴͰ࢖ΘΕ͍ͯΔDSL΋࣮͸ͨͩͷϝιου • DSL͸ʮఆٛʯʹڧ͍ •

    ΠϯλʔϑΣΠε͸ʮ७ਮͳϝιουʯͱDSLʹ෼͚ΒΕΔ
  42. https://rubykaigi.org/2019/ presentations/tanaka_akr.html

  43. ྑ͍ΠϯλʔϑΣΠεͬͯ ͳΜͩΖ͏ʁʁʁ

  44. ⚠ ͜Ε͸͢΂ͯࢲͷ୯ͳΔҰҙݟͰ͢ Ͳ͔ͬͪͱ͍͏ͱ൓࿦͕΄͍͠… ࠙਌ձͰ͓࿩͠·͠ΐ͏

  45. ྑ͍ΠϯλʔϑΣΠεͷ̏ݪଇ • ໎Θͳ͍ • ґଘ͠ͳ͍ • ೚ͤ͗͢ͳ͍

  46. ໎Θͳ͍ • ϝιου໊ʹࡾ୯ݱͷʮsʯ͸ඞཁ͚ͩͬʁ • ͋ͷΫϥε͸callͰݺͿΜ͚ͩͬɺperform͚ͩͬʁ • Πϯελϯεϝιου͚ͩͬɺΫϥεϝιου͚ͩͬʁ • Ҿ਺ͷॱং͸ʁ

  47. ґଘ͠ͳ͍ • ϝιουνΣʔϯΛલఏͱ͠ͳ͍ʢಛఆͷฦΓ஋ʹґଘ͠ͳ ͍ʣ • ςετ࣌ͷελϒ͕ߴʑҰͭͰࡁΉ

  48. ೚ͤ͗͢ͳ͍ • ΤϯυϢʔβʔ͕ࣗྗͰͰ͖Δ͜ͱ͸΍Βͳ͍ • ୯७ͳόϦσʔγϣϯʹෳࡶͳDSL͸ຊ౰ʹඞཁ͔ʁ • ΤϯυϢʔβʔ͕ࣗྗͰ΍ΓͮΒ͍͜ͱΛ΍Δ • νΣʔϯͨ͠ϩʔϧόοΫॲཧ͸ࣗྗͰ͸೉͍͠ʢޙड़ʣ

  49. ௨ৗͷϝιου͔DSL͔ɺ ͦΕ͕໰୊ͩ

  50. શ෦ϝιουͰ͍͍͡ΌΜɺ DSLͱ͔֮͑Δͷେมͩ͠ʂ Pure Ruby࠷ߴʂ

  51. ͱࢥͬͯͨ࣌ظ͕๻ʹ΋͋Γ·ͨ͠…

  52. ϝιουΠϯλʔϑΣΠεͷ௕ॴ • Ҿ਺΍selfͳͲ͕ࣗ໌ • ܧঝͨ͠ͱ͖ʹಈ࡞͕ཧղ͠΍͍͢ • ͦ͜ʹʮࠇຐज़ʯ͸ͳ͍

  53. ϝιουΠϯλʔϑΣΠεͷ୹ॴ • ॊೈͳڍಈΛఏڙ͢ΔࡍʹϢʔβʔ͕ॻ͘΂͖ϝιου͕൥ࡶ ʹͳΓ͕ͪ • ϥΠϒϥϦ͕ϑϩʔΛίϯτϩʔϧ͠Α͏ͱ͢Δࡍʹඞཁͳ ϑοΫΛࠩ͠ڬΉͷ͕೉͍͠ʢϢʔβʔʹଟ਺ͷϝιουΛఆ ٛͯ͠΋Β͏ඞཁ͕ग़ͯ͘Δʣ

  54. DSLͷ௕ॴ • ϒϩοΫҾ਺͸ϝιουҾ਺ΑΓॊೈ • ద੾ʹ໋໊͞Ε͍ͯΔ৔߹ɺՄಡੑ͕ߴ͍ • ϥΠϒϥϦ͕೚ҙͷॲཧΛϢʔβʔఆٛͷॲཧʹڬΈࠐΊΔ ʢϑοΫ΍ΩϟογϡͳͲʣ • ԿΛ͍ͨ͠ͷ͔ͷʮఆٛʯΛએݴతʹॻ͚Δ

  55. DSLͷ୹ॴ • ʮࠇຐज़ʯ͕ଟ͘ͳΓ͕ͪͷͰɺڍಈΛਖ਼֬ʹ೺Ѳ͢Δͷ͕ࠔ ೉ • ద੾ʹ໋໊͞Ε͍ͯͳ͍৔߹ɺՄಡੑ͕ஶ͘͠མͪΔέʔε͕ ͋Δ • ϝλϓϩάϥϛϯάΛར༻͢Δ৔߹ɺσόοά͕ࠔ೉ʹͳΔ

  56. ॊೈੑͷ఺ͰDSL͕༏Ґ

  57. ͡Ό͋શ෦DSLΛ༻ҙ͠·͘Ε͹ ͦΕͰ͍͍ͷ͔ʂʁ

  58. ࠇຐज़͡Όͳ͍ͷͦΕʁ

  59. DSL͸ຐज़౓͕௿͍ ʢby Joker1007ʣ

  60. ൑அ͕೉͍͠έʔε΋

  61. ྫɿ όϦσʔγϣϯ͸ఆٛͳͷͰDSLΛ࢖͏ ͔͠͠ɺܕνΣοΫΛDSLͰߦ͏΂͖͔ʁ

  62. ճ౴ྫɿ ೚ͤ͗͢ͳ͍ݪଇʹै͍ɺ࣮ࡍͷ όϦσʔγϣϯ͸Ϣʔβʔʹ೚ͤΔɺ ϥΠϒϥϦ͸όϦσʔγϣϯఆٛͷ ϑοΫDSLͷΈఏڙ

  63. ۩ମྫ ʢࠓճͷυϝΠϯ͸ίϚϯυύλʔϯʣ

  64. Neco͸ϏδωεϩδοΫΛ ʮίϚϯυʯʹ෼ׂ͠ɺ ͦΕΒΛ૊Έ߹ΘͤΔϑϩʔΛ ࢧԉ͢ΔϥΠϒϥϦ

  65. ·ͱΊ • ͔ͤͬ͘RubyͰॻ͍ͯΔΜ͔ͩΒΠϯλʔϑΣΠεʹ͸ͩ͜Θ Γ͍ͨʢ࢖ָ͍ͬͯ͠ϥΠϒϥϦ͕΄͍͠ʣ • DSL͸RubyͷڧΈͰ΋͋Γɺద੾ʹ໋໊ɾ࣮૷͢Ε͹୯७ͳϝ ιουΑΓॊೈͳఆٛΠϯλʔϑΣΠεΛఏڙͰ͖Δ • ͕Μ͹ͬͯॊೈͳ࢖͍উखΛ໨ࢦͯ͠ΔͷͰNeco࢖ͬͯ͘ΕΑͳʢએ఻ʣ