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

After A Decade: Still a Rubyist - Red Dot Ruby ...

hone
June 24, 2016

After A Decade: Still a Rubyist - Red Dot Ruby Conference 2016

Ruby isn't new or hip, but that's ok. It's a safe choice, which means we're now legacy and powering larger data systems, which is a good thing(™). This hardly means Ruby is boring. It's great to learn the next new thing (and you should!), but that doesn't mean you can't continue to build your next project in Ruby. The community is working on some initiatives to pave a bright future for Ruby. In this talk, we're going to touch on three specific projects that are interesting and applicable to the everyday Rubyist.

Reactive Programming think Node.js (jruby/ratpack)
Ruby Performance in modern APIs and Web Apps (helix/rust)
Scripting / CLI tools in Ruby (mruby/mruby-cli)

Even after 10 years, I've never been more excited to build things in Ruby!

Learn More Links:

* https://hrku.com/jrubrat
* http://blog.skylight.io/introducing-helix/
* http://mruby-cli.org

Video: https://engineers.sg/video/closing-keynote-after-a-decade-still-a-rubyist-reddotrubyconf-2016--824

hone

June 24, 2016
Tweet

More Decks by hone

Other Decks in Programming

Transcript

  1. #rubykaraoke details 10pm Tonight (after the after party) K BOX

    @ Chinatown $38++ pax 211 New Bridge Road #04-01 Lucky Chinatown Singapore 059432
  2. Ruby has many secrets. #1: Predefined Variables #2: ?, =>

    "," #3: [1,2,3]*? => "1,2,3" #4: "Hello"[/[A-Z]/] => "H"
  3. The "fish" in our industry is the ability to think

    abstractly and knowing what to do when the abstraction eventually leaks.
  4. Unlike documentation, running Ruby (language) tests is easy. It's only

    6 steps! $ git clone https://github.com/ruby/ruby $ cd ruby $ autoconf $ ./configure --disable-install-doc $ make -j $ make check
  5. "[Node.js] ran really efficiently in terms of its I/O utilization,

    and its memory utilization is really low […] You’re not really CPU-bound anymore. You’re memory bound and I/O bound." Kiran Prasad senior director of mobile engineering LinkedIn www.datacenterknowledge.com/archives/2013/12/04/paypal-groupon-go-node-js/
  6. Ratpack is a micro-framework for building modern HTTP applications with

    reactive principles in mind. It is built on the highly performant and efficient Netty event-driven networking engine.
  7. By leveraging powerful concurrency libraries from the JVM, ratpack is

    built from the ground up to support non-blocking IO.
  8. ratpack streaming RatpackServer.start do |b| b.handlers do |chain| chain.get("stream") do

    |ctx| publisher = Streams.periodically(ctx, Duration.ofMillis(1000)) do |i| i < 10 ? i.to_s : nil end ctx.render(ResponseChunks.stringChunks(publisher)) end end end
  9. ratpack IO code RatpackServer.start do |b| b.handlers do |chain| chain.get("io")

    do |ctx| Blocking.get do sleep 0.3 end.then do ctx.render("Got response from fake db!") end end end end
  10. ActiveSupport's String#blank? class String # A string is blank if

    it's empty or contains whitespaces only: # # ''.blank? # => true # ' '.blank? # => true # "\t\n\r".blank? # => true # ' blah '.blank? # => false # # Unicode whitespace is supported: # # "\u00a0".blank? # => true # def blank? /\A[[:space:]]*\z/ === self end end
  11. fast_blank static VALUE rb_str_blank(VALUE str) { rb_encoding *enc; char *s,

    *e; enc = STR_ENC_GET(str); s = RSTRING_PTR(str); if (!s || RSTRING_LEN(str) == 0) return Qtrue; e = RSTRING_END(str); while (s < e) { int n; unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); switch (cc) { case 9: case 0xa: case 0xb: case 0xc: case 0xd: case 0x20: case 0x85: case 0xa0: case 0x1680: case 0x2000: case 0x2001: case 0x2002: case 0x2003: case 0x2004: case 0x2005: case 0x2006: case 0x2007: case 0x2008: case 0x2009: case 0x200a: case 0x2028: case 0x2029: case 0x202f: case 0x205f: case 0x3000: /* found */ break; default: return Qfalse; } s += n; } return Qtrue; }
  12. Rust is a systems programming language that runs blazingly fast,

    prevents segfaults, and guarantees thread safety.
  13. blank.rs pub extern "C" fn fast_blank(buf: Buf) -> bool {

    buf.as_slice().chars().all(|c| c.is_whitespace()) }
  14. Benchmarks (Higher is Better) =========== Test String Length: 6 ===========

    Rust 11.043M (± 3.5%) i/s - 54.744M C 10.583M (± 8.5%) i/s - 52.464M Ruby 964.469k (±27.6%) i/s - 4.390M
  15. Helix is a bridge between Ruby and Rust. It allows

    you to write Ruby classes in Rust without having to write the glue code yourself.
  16. fast_blank in helix #[macro_use] extern crate helix; declare_types! { reopen

    class RubyString { def is_blank(self) -> bool { self.chars().all(|c| c.is_whitespace()) } } }
  17. hk

  18. mruby mruby is the lightweight implementation of the Ruby language

    complying with part of the ISO standard. mruby can be linked and embedded within your application.
  19. mrblib ├── [4.0K] mrblib │ ├── [4.0K] mruby-cli │ │

    ├── [ 697] cli.rb │ │ ├── [ 424] help.rb │ │ ├── [ 403] option.rb │ │ ├── [1022] options.rb │ │ ├── [8.0K] setup.rb │ │ ├── [ 238] util.rb │ │ └── [ 206] version.rb │ └── [ 53] mruby-cli.rb
  20. MRI # hello_world.rb puts 'Hello World' $ time ruby hello.rb

    Hello World real 0m0.041s user 0m0.028s sys 0m0.008s
  21. MRI # hello_world.rb puts 'Hello World' $ time ruby hello.rb

    Hello World real 0m0.041s user 0m0.028s sys 0m0.008s # mrblib/hello.rb def __main__(argv) puts "Hello World" end $ time mruby/build/host/bin/hello Hello World real 0m0.003s user 0m0.000s sys 0m0.000s mruby-cli
  22. MRI # hello_world.rb puts 'Hello World' $ time ruby hello.rb

    Hello World real 0m0.041s user 0m0.028s sys 0m0.008s # mrblib/hello.rb def __main__(argv) puts "Hello World" end $ time mruby/build/host/bin/hello Hello World real 0m0.003s user 0m0.000s sys 0m0.000s mruby-cli
  23. Hello World Example $ mruby-cli --setup hello $ cd hello

    $ docker-compose run compile $ docker-compose run shell # mruby/build/host/bin/hello
  24. Hello World Example $ mruby-cli --setup hello $ cd hello

    $ docker-compose run compile $ docker-compose run shell # mruby/build/host/bin/hello Hello World
  25. Hello World Example $ mruby/bin/mruby-cli --setup hello create .gitignore create

    mrbgem.rake create build_config.rb create Rakefile create Dockerfile create docker-compose.yml create tools/ create tools/hello/ create tools/hello/hello.c create mrblib/ create mrblib/hello.rb create mrblib/hello/ create mrblib/hello/version.rb create bintest/ create bintest/hello.rb create test/ create test/test_hello.rb