RailsとYesodの比較

 RailsとYesodの比較

Ceda558ac47bd7af518c12a51614664a?s=128

Fujimura Daisuke

April 21, 2012
Tweet

Transcript

  1. RailsͱYesodͷൺֱ ౻ଜେհ Sunday, April 22, 12

  2. ࣗݾ঺հ • ౻ଜେհ • גࣜձࣾAiming • @ffu_ • http://fujimuradaisuke.com Sunday,

    April 22, 12
  3. ࣗݾ঺հ (2) Rubyͱࢲ • ੲ͸ABAPerͩͬͨɻ·ͱ΋ͳݴޠ͕΍Γͨ͘ͳΓRubyʹస޲ • ͔Ε͜Ε3೥൒͘Β͍ϑϧλΠϜͰRailsͷ࢓ࣄΛͯ͠Δ • Railsίϛολ @a_matsuda

    ࢓ࣄͯ͠Rails಺෦ʹ͚ͬ͜͏ৄ͘͠ͳͬͨ • WEB+DB PRESSͷRails3ಛूΛͪΐͬͱख఻ͬͨ • Railsͷ࡞ऀɺDHHͱ൴ͷಇ͘37signalsͷϑΝϯ Sunday, April 22, 12
  4. ࣗݾ঺հ (3) Haskellͱࢲ • The Little SchemerͰؔ਺ϓϩάϥϛϯάΛ஌Δ • Seven Languages

    in Seven WeeksͰHaskellΛ஌Δ • ελʔτHaskellͰຊ֨తʹHaskell͕޷͖ʹͳΔ • ݱࡏɺձࣾͰYesodΛࢼݧతʹಋೖத Sunday, April 22, 12
  5. ΞδΣϯμ • Railsʹ͋ͬͯYesodʹͳ͍΋ͷ঺հ • Rails࢖͍͔ΒݟͨYesod(ͱHaskell)ͷ͍͍ͱ͜Ζ • Yesodʹཉ͍͠΋ͷ঺հ Sunday, April 22,

    12
  6. Yesodʹͳ͍΋ͷ(1) σϓϩΠπʔϧ • Railsʹ͸Capistranoͱ͍͏σϓϩΠࣗಈԽπʔϧ͕͋Γ·͢ɻ • $ cap deploy ͰσϓϩΠ •

    $ cap deploy:rollbackͰલճσϓϩΠͨ͠ίʔυʹϩʔϧόοΫ • ͦͷଞɺSSHͰೖͬͯσϓϩΠ࣌ʹߦ͏࡞ۀͷࣗಈԽҰൠ͕ՄೳͰ͢ɻ • https://github.com/capistrano/capistrano/wiki/2.x-Getting-Started Sunday, April 22, 12
  7. Yesodʹͳ͍΋ͷ(1) σϓϩΠπʔϧ • cabal-dev Λ࢖ͬͨΒͰ͖·ͨ͠… • ͨͩ͠ຖճશґଘϥΠϒϥϦΛΠϯετʔϧ͢ΔͷͰ͕͔͔࣌ؒΔ • ͦ΋ͦ΋Haskellerͱͯ͠͸ʮRubyͷπʔϧΛ࢖͏ʯͰOKͳͷ͔ʁ Sunday,

    April 22, 12
  8. Yesodʹͳ͍΋ͷ(2) CRUDͷੜ੒ • Rails͸scaffoldͰCRUD͕Ͱ͖Δίʔυ͕ੜ੒͞Ε·͢ɻ • ͜ͷҐͷίʔυ͕ ੜ੒͞ΕΔ • RailsྲྀͷRESTfulͳϧʔςΟϯάʹԊͬͨίʔυ͕ੜ੒͞ΕΔͷͰɺͦΕΛݩ ʹ։ൃ͍ͯ͠Ε͹ɺࣗવͱRailsతͳΘ͔Γ΍͍͢ίʔυʹͳΓ·͢ɻ

    • ࣗવͱRails wayͰ։ൃ͢Δ͜ͱʹͳΔͷͰɺ೰·ͳ͍ͰࡁΉͱ͍͏ར఺΋ɻ • YesodͰ΋೰·ͣ։ൃΛਐΊΒΕΔఔ౓ʹscaffoldͰίʔυΛੜ੒ͯ͠΄͠ ͍ɻ Sunday, April 22, 12
  9. Yesodʹͳ͍΋ͷ(3) RSpec • ΄΅σϑΥϧτ࠾༻͞ΕͯΔςετϑϨʔϜϫʔΫɻ • ಈ࡞ݕূͰ͸ͳ͘ιϑτ΢ΣΞͷʮৼΔ෣͍ʯΛܾΊΔͨΊͷϥΠϒϥϦ • http://jp.rubyist.net/magazine/?0021-Rspec ʹ֓ཁ͕·ͱ·ͬͯ·͢ɻ •

    rspec-railsͱ͍͏ϥΠϒϥϦͰRailsͷςετ͕ܹ͘͠ੜ࢈తʹͳΓ·͢ɻ • ͦͷଞपลϥΠϒϥϦଟ਺ɻ Sunday, April 22, 12
  10. ͳͥRSpec͕ཉ͍͔͠ • RSpec͸ઃܭπʔϧͱͯ͠ຊ౰ʹ༏लɻ·ͣSpecΛεέονײ֮Ͱॻ͍ͯҰ ୴ઃܭΛจষԽ͢ΔͱɺAPIશମ͕ݟ௨ͤΔΑ͏ʹͳΓ·͢ɻ͜͜Ͱઃܭͷྑ ͠ѱ͠Λݕ౼Ͱ͖Δͷ͸ૉ੖Β͍͠Ͱ͢ɻ ͜Μͳ۩߹ʹઃܭΛઌʹॻ͘ ࣮ߦ͢Δͱ“PENDING” Sunday, April 22,

    12
  11. ͳͥRSpec͕ཉ͍͔͠ • request spec΋ཉ͍͠Ͱ͢ɻrequest spec͸SeleniumͳͲͰ࣮ࡍʹΞϓϦέʔ γϣϯΛಈ͔ͯ͠ɺϑϩϯτΤϯυ͔ΒΞϓϦέʔγϣϯΛݕࠪ͢Δ࢓૊ Έɻclick_link(‘#submit-button’)ͱ͍ͬͨײ͡ͰखಈͰ͍ͯͨ͠ಈ࡞֬ೝΛࣗ ಈԽͰ͖·͢ɻ • ਅ݋ʹॻ͘ͱɺ࣮ߦՄೳͳड͚ೖΕςετܭըॻʹͳΓ·͢ɻ

    • ෳ਺ͷػೳΛ·͙ͨγφϦΦςετ͕ॻ͖΍͍͢ɻ • ͜͜਺೥ɺRails͸͜ͷϨΠϠʔ·Ͱςετ͢Δͷ͕σϑΥϧτɻ Sunday, April 22, 12
  12. ͳ͍΋ͷ(3) RSpec • ͪͳΈʹHaskellͰ΋hspecͱ͍͏RSpecతͳϥΠϒϥϦ͕͋Γ·͢ɻ • http://hspec.github.com/ • ࠷ۙ1.1ʹͳΓ·ͨ͠ʂ • ͔͠͠ɺdescribe/contextͷೖΕࢠ͸Ͱ͖ͳ͍͠ɺsetup/teardownແ͍͠ɺ

    RSpecʹࣅͨߏจͷxUnitͱ͍͏ͷ͕࣮৘…ɻ • ࠓޙʹظ଴ɻ Sunday, April 22, 12
  13. Rails࢖͍͔ΒݟͨYesod(ͱHaskell)ͷ͍͍ͱ͜Ζ • NullPointerException͕ແ͍ʂ • ܕΛ͋ΘͤΔͱ͍͍ͩͨظ଴௨Γʹಈ͘ • undefinedΛ࢖͏ͱςετίʔυͳ͠ͰBDDͬΆ͍͜ͱ͕Ͱ͖Δ • ى͜Γ͏Δ͜ͱΛશ෦ߟྀ͠ͳ͍ͱ͍͚ͳ͍ͷͰɺ૝ఆ΋Εͷόά͕ͳ͘ͳ Δ

    • ΞυϗοΫଟ૬͕RubyͷMix-inͱࣅ͍ͯΔͷͰ਌͠Έ΍͍͢ Sunday, April 22, 12
  14. Yesodʹཉ͍͠΋ͷ(1) • ϏδωεϩδοΫΛهड़͢ΔͨΊͷϥΠϒϥϦ • PersistentΑΓ΋͏ͪΐͬͱந৅౓ߴ͍هड़͕͍ͨ͠Ͱ͢ɻ • RailsͰ͸ActiveRecordͰϢʔβʔͷϝϯλϧϞσϧʹ͍ۙܗͷදݱ͕Ͱ͖ ͨɻ • ͱ͍ͬͯ΋ORϚούʔΛ࡞Δͷ΋ҧ͍·͢ΑͶɻDCI

    ͕ࢀߟʹͳΔؾ͕͠ ͍ͯ·͢ɻ • ࡞ͬͯΈ͍ͨͰ͢ɻ Sunday, April 22, 12
  15. Yesodʹཉ͍͠΋ͷ(2) • Yesod way • Railsʹ͸Ϩʔϧ͕͋ͬͯɺͦΕʹ৐ΕΔɻ • DHHᐌ͘ʮConstraints are liberatingʯ

    • ࠓͷͱ͜ΖYesodʹ͸Ϩʔϧ͕ݟ౰ͨΒͳ͍ɻ Sunday, April 22, 12
  16. ͓ΘΓ • ए͍ϥΠϒϥϦͳͷͰɺࠓޙʹظ଴Ͱ͢ Sunday, April 22, 12

  17. ༨ஊ • ςϯϓϨʔτΤϯδϯͷ࿩͸…ʁ • ձࣾͰ࡞ͬͯΔͷ͸JSON APIͳͷͰɺ৮ͬͯͳ͍ΜͰ͢ɻ • ΋͠΍ΔͳΒmustacheΛ࢖͏ͱࢥ͍·͢ɻShakespearean Templates͸ϑ ϩϯτΤϯυͷਓͱͷίϥϘϨʔγϣϯ͕೉ͦ͠͏ͳҹ৅Ͱ͢ɻ

    • scotty΋ؾʹͳͬͯ·͢ • Web API࡞ΔͷͰ͋Ε͹ͬͪ͜ͷ΄͏͕खܰͦ͏ Sunday, April 22, 12