Programming Language Crystal

Programming Language Crystal

#w8lt 第四回 (2015-07-29) の発表資料です
http://w8lt.connpass.com/event/16856/

92ce4587cc8465736433e698b1e50aaa?s=128

Daisuke Fujita

July 29, 2015
Tweet

Transcript

  1. Programming Language Crystal 2015-07-29 W8LT#4 @dtan4 IUUQTqJDLSQLZ[T

  2. TF[FNJ
 ͪͦ͝͏͞·Ͱ͢

  3. ಙాݚ.

  4. IUUQTDSZTUBMTI

  5. IUUQTDSZTUBMTI

  6. IUUQDSZTUBMMBOHPSH

  7. Crystal • Ruby ͬΆ͍γϯλοΫε • ੩తܕνΣοΫ • Crystal ͷίʔυ಺Ͱ C

    ॻ͚Δ • ωΠςΟϒίʔυੜ੒ • Crystal -> LLVM IR -> ωΠςΟϒ http://crystal-lang.org/ https://github.com/manastech/crystal
  8. • ίϯύΠϥ͕ Crystal Ͱ࣮૷͞ΕͯΔ (!) Crystal http://crystal-lang.org/ https://github.com/manastech/crystal

  9. Crystal • Initial commit ͸ 2012-09-04 • v0.1.0 ͸ 2014-06-19

    • ݱࡏ͸ v0.7.4 (2015-06-24) http://crystal-lang.org/ https://github.com/manastech/crystal
  10. Crystal • Πϯετʔϧ (Mac OS X): • Try it online:

    http://play.crystal-lang.org/ $ brew tap manastech/crystal $ brew update $ brew install crystal-lang
  11. Crystal • Πϯετʔϧ (Mac OS X): • Try it online:

    http://play.crystal-lang.org/ $ brew tap manastech/crystal $ brew update $ brew install crystal-lang CSFXOQNͰDSZTUBMೖΕͯΔͱ
 1"5)ʹΑͬͯ͸Ϳ͔ͭΔ Ϳ͔ͭͬͨ DSZTUBM͸
 ·͕͍ͪ
  12. Crystal • εΫϦϓτ࣮ߦ • όΠφϦϏϧυ & ࣮ߦ: • ࠷దԽϏϧυ &

    ࣮ߦ $ crystal [run] hoge.cr $ crystal build hoge.cr $ ./hoge $ crystal build hoge.cr --release $ ./hoge
  13. Ruby ͱͷҧ͍ • Ҿ਺ʹܕࢦఆͰ͖Δ def hoge(n : Int) • γϯάϧΫΥʔτͩΊ

    • Bool ஋͸ Bool ϦςϥϧɺΫϥε͡Όͳ͍ • RubyGems తͳύοέʔδγεςϜແ͍ • (crystal#220) • ࣗલͷґଘ؅ཧγεςϜ͕͋Δ $ crystal deps • ඪ४ϥΠϒϥϦʹ͍Ζ͍ΖἧͬͯΔ • ͳͲͳͲ $VSTFT )551 .BSLEPXO 0"VUI 4QFDʜ
  14. ϕϯνϚʔΫ

  15. ஛಺ؔ਺ #!/usr/bin/env crystal def tarai(x, y, z) return y if

    x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0) #!/usr/bin/env ruby def tarai(x, y, z) return y if x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0)
  16. ஛಺ؔ਺ #!/usr/bin/env crystal def tarai(x, y, z) return y if

    x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0) #!/usr/bin/env ruby def tarai(x, y, z) return y if x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0) ιʔείʔυ͸ શ͘ಉ͡ ճ UBSBJݺͼग़͠
  17. ஛಺ؔ਺ 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ UBSBJ 

      T T T T
  18. ஛಺ؔ਺ 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ UBSBJ 

      T T T T ͦͷ··Y όΠφϦϏϧυY
  19. ؆୯ͳ HTTP αʔό #!/usr/bin/env crystal require "http/server" server = HTTP::Server.new(8080)

    do |request| HTTP::Response.ok "text/plain", "Hello world!" end server.listen #!/usr/bin/env ruby require "rack" app = Proc.new do |env| ["200", { "Content-Type" => "text/plain" }, ["Hello world!"]] end Rack::Handler::WEBrick.run(app, Port: 8080)
  20. ؆୯ͳ HTTP αʔό 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ

    ฒྻ SFRT 
 SFRT 
 SFRT 
 SFRT  SFRT $ ab -k -c 10 -n 10000 http://localhost:8080/
  21. ؆୯ͳ HTTP αʔό 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ

    ฒྻ SFRT 
 SFRT 
 SFRT 
 SFRT  SFRT $ ab -k -c 10 -n 10000 http://localhost:8080/ ͦͷ··Y ࠷దԽϏϧυY
  22. WAF • Codcore/amethyst (ࢵਫথ) • Rails ͬΆ͍΍ͭ • druvrajvanshi/Moonshine •

    Sinatra ͬΆ͍΍ͭ
  23. ॴײ • ஌໊౓௿͍ • άάϥϏϦςΟ௿͍ • Go ͸όΠφϦు͚Δ͚Ͳจ๏͕…ͱ͍͏
 Rubyist ʹ΢έ͕ྑͦ͞͏

    • Ruby ք۾ͷࢿ࢈ΛҠ২͠΍ͦ͢͏ • ΤίγεςϜڵོͯ͠΄͍͠