$30 off During Our Annual Pro Sale. View Details »

Programming Language Crystal

Programming Language Crystal

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

Daisuke Fujita

July 29, 2015
Tweet

More Decks by Daisuke Fujita

Other Decks in Technology

Transcript

  1. Programming Language
    Crystal
    2015-07-29

    W8LT#4

    @dtan4
    IUUQTqJDLSQLZ[T

    View Slide


  2. TF[FNJ

    ͪͦ͝͏͞·Ͱ͢

    View Slide

  3. ಙాݚ.

    View Slide

  4. IUUQTDSZTUBMTI

    View Slide

  5. IUUQTDSZTUBMTI

    View Slide

  6. IUUQDSZTUBMMBOHPSH

    View Slide

  7. Crystal
    • Ruby ͬΆ͍γϯλοΫε

    • ੩తܕνΣοΫ

    • Crystal ͷίʔυ಺Ͱ C ॻ͚Δ

    • ωΠςΟϒίʔυੜ੒

    • Crystal -> LLVM IR -> ωΠςΟϒ
    http://crystal-lang.org/
    https://github.com/manastech/crystal

    View Slide

  8. • ίϯύΠϥ͕ Crystal Ͱ࣮૷͞ΕͯΔ (!)
    Crystal
    http://crystal-lang.org/
    https://github.com/manastech/crystal

    View Slide

  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

    View Slide

  10. Crystal
    • Πϯετʔϧ (Mac OS X):

    • Try it online:
    http://play.crystal-lang.org/
    $ brew tap manastech/crystal
    $ brew update
    $ brew install crystal-lang

    View Slide

  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͸

    ·͕͍ͪ

    View Slide

  12. Crystal
    • εΫϦϓτ࣮ߦ

    • όΠφϦϏϧυ & ࣮ߦ:

    • ࠷దԽϏϧυ & ࣮ߦ
    $ crystal [run] hoge.cr
    $ crystal build hoge.cr
    $ ./hoge
    $ crystal build hoge.cr --release
    $ ./hoge

    View Slide

  13. Ruby ͱͷҧ͍
    • Ҿ਺ʹܕࢦఆͰ͖Δ def hoge(n : Int)
    • γϯάϧΫΥʔτͩΊ

    • Bool ஋͸ Bool ϦςϥϧɺΫϥε͡Όͳ͍

    • RubyGems తͳύοέʔδγεςϜແ͍

    • (crystal#220)

    • ࣗલͷґଘ؅ཧγεςϜ͕͋Δ $ crystal deps

    • ඪ४ϥΠϒϥϦʹ͍Ζ͍ΖἧͬͯΔ

    • ͳͲͳͲ
    $VSTFT )551 .BSLEPXO 0"VUI 4QFDʜ

    View Slide

  14. ϕϯνϚʔΫ

    View Slide

  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)

    View Slide

  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ݺͼग़͠

    View Slide

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

    View Slide

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

    View Slide

  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)

    View Slide

  20. ؆୯ͳ HTTP αʔό
    3VCZ
    $SZTUBM
    ͦͷ··
    $SZTUBM
    Ϗϧυࡁ
    $SZTUBM
    ࠷దԽࡁ
    ฒྻ
    SFRT

    SFRT

    SFRT

    SFRT

    SFRT
    $ ab -k -c 10 -n 10000 http://localhost:8080/

    View Slide

  21. ؆୯ͳ HTTP αʔό
    3VCZ
    $SZTUBM
    ͦͷ··
    $SZTUBM
    Ϗϧυࡁ
    $SZTUBM
    ࠷దԽࡁ
    ฒྻ
    SFRT

    SFRT

    SFRT

    SFRT

    SFRT
    $ ab -k -c 10 -n 10000 http://localhost:8080/
    ͦͷ··Y
    ࠷దԽϏϧυY

    View Slide

  22. WAF
    • Codcore/amethyst (ࢵਫথ)

    • Rails ͬΆ͍΍ͭ

    • druvrajvanshi/Moonshine

    • Sinatra ͬΆ͍΍ͭ

    View Slide

  23. ॴײ
    • ஌໊౓௿͍

    • άάϥϏϦςΟ௿͍

    • Go ͸όΠφϦు͚Δ͚Ͳจ๏͕…ͱ͍͏

    Rubyist ʹ΢έ͕ྑͦ͞͏

    • Ruby ք۾ͷࢿ࢈ΛҠ২͠΍ͦ͢͏

    • ΤίγεςϜڵོͯ͠΄͍͠

    View Slide