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

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

B87c43d4be875c9b41cd436f5c364f75?s=47 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

B87c43d4be875c9b41cd436f5c364f75?s=128

hone

June 24, 2016
Tweet

Transcript

  1. After A Decade Still a Rubyist

  2. Terence Lee @hone02

  3. Austin, TX

  4. None
  5. None
  6. None
  7. #soloselfie

  8. #rubykaraoke

  9. @aspleenic

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

    @ Chinatown $38++ pax 211 New Bridge Road #04-01 Lucky Chinatown Singapore 059432
  11. Red Dot Ruby Conference in Review

  12. 10 Years of Ruby SG

  13. There are two hard things in computer science: cache invalidation,

    naming things, and off-by-one errors.
  14. There are two hard things in computer science: cache invalidation,

    naming things, and off-by-one errors.
  15. I'll just use this regular expression: /[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)/

  16. Ruby has many secrets. #1: Predefined Variables #2: ?, =>

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

    abstractly and knowing what to do when the abstraction eventually leaks.
  19. Probably your API is fast enough

  20. Google Lies. People don't leave because of managers

  21. 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
  22. If there are no tests, there'd be no slow tests

  23. Future authorization systems should be less dependent on the developer

    and give more power to the users
  24. A change positive architecture provides maintainable, sustainable, and joyful development

  25. Always Be Simulating

  26. None
  27. Daru

  28. Currencies are tricky. Salaries

  29. There are two hard things in computer science: cache invalidation,

    naming things, and off-by-one errors.
  30. IoT makes a lot of sense

  31. An existing system being used reflects its real needs.

  32. Three years on a cold stone will make the stone

    warm
  33. Don't believe in Stars

  34. explainshell.com

  35. Declarative Paradigms can make it easier to reason about your

    app
  36. In theory, theory and practice are the same...

  37. Regular Expressions: Now you have two problems

  38. My Ruby Story

  39. None
  40. None
  41. None
  42. Started Learning Ruby in 2006

  43. None
  44. After 10 years, Why Ruby?

  45. Community

  46. Other Languages

  47. Ruby isn't cool anymore

  48. People Leaving Ruby blog.jaredfriedman.com/2015/09/15/why-i-wouldnt-use-rails-for-a-new- company/

  49. Mature Ecosystem

  50. "Bro, I wrote a script in Ruby Today. It felt

    freeing." -Yehuda Katz
  51. Edges of Ruby

  52. Fast is a feature

  53. Ruby 3x3

  54. Ruby 10% Year over Year

  55. Thanks Ruby Core Team, AppFolio, Heroku <3

  56. "[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/
  57. Node.js is great at building efficient web services with lots

    of I/O
  58. ratpack.io

  59. 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.
  60. What's "reactive" actually mean?

  61. applying backpressure from a client non-blocking communication

  62. non-blocking communication

  63. By leveraging powerful concurrency libraries from the JVM, ratpack is

    built from the ground up to support non-blocking IO.
  64. ratpack hello world RatpackServer.start do |b| b.handlers do |chain| chain.get

    do |ctx| ctx.render("Hello World!") end end end
  65. 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
  66. 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
  67. Faban Benchmarks

  68. Learn more: hrku.co/jrubrat

  69. CPU Bound

  70. In 5 samples, ActiveSupport#blank? makes up 3.88% of total CPU

    time github.com/rails/rails/pull/9958
  71. 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
  72. CPU Bound -> Native Extensions

  73. 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; }
  74. Up to 20X faster 5% improvement on macro benchmarks

  75. Becoming good at writing safe C is hard

  76. issues even for seasoned maintainers C Extensions are Hard

  77. None
  78. Rust is a systems programming language that runs blazingly fast,

    prevents segfaults, and guarantees thread safety.
  79. If you have successfully compiled a Rust program, it will

    not segfault at runtime.
  80. Zero-Cost Abstractions blog.rust-lang.org/2015/05/11/traits.html

  81. blank.rs pub extern "C" fn fast_blank(buf: Buf) -> bool {

    buf.as_slice().chars().all(|c| c.is_whitespace()) }
  82. 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
  83. None
  84. helix

  85. None
  86. 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.
  87. 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()) } } }
  88. TurboRails?

  89. Learn more: blog.skylight.io/introducing-helix/

  90. Packaging in Ruby

  91. story of the heroku toolbelt

  92. gem install heroku

  93. Requires Ruby to be installed

  94. Can't guarantee same version of ruby locally

  95. None
  96. Packaging was a nightmare

  97. hk

  98. None
  99. require in ruby is slow

  100. None
  101. None
  102. No Great Packaging Story in Ruby

  103. mruby-cli

  104. 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.
  105. writing in ruby

  106. 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
  107. fast is a feature

  108. MRI # hello_world.rb puts 'Hello World' $ time ruby hello.rb

    Hello World real 0m0.041s user 0m0.028s sys 0m0.008s
  109. 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
  110. 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
  111. No require

  112. a single binary for every major platform

  113. docker-compose run compile Linux OS X Windows

  114. Size Matters $ ls -nlh mruby-cli | awk '{print $5}'

    421K
  115. simple setup

  116. Docker FROM hone/mruby-cli

  117. Hello World Example $ mruby-cli --setup hello

  118. Hello World Example $ mruby-cli --setup hello $ cd hello

  119. Hello World Example $ mruby-cli --setup hello $ cd hello

    $ docker-compose run compile
  120. Hello World Example $ mruby-cli --setup hello $ cd hello

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

    $ docker-compose run compile $ docker-compose run shell # mruby/build/host/bin/hello Hello World
  122. 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
  123. edit mrblib/hello.rb # mrblib/hello.rb def __main__(argv) puts "Hello World" end

  124. Learn more: mruby-cli.org

  125. None
  126. Even after 10 years, I've never been more excited to

    build things in Ruby.
  127. None
  128. Let's keep writing the Ruby we love without the fear

    we'll hit a wall.
  129. Thank You Red Dot Ruby @hone02