Slide 1

Slide 1 text

After A Decade Still a Rubyist

Slide 2

Slide 2 text

Terence Lee @hone02

Slide 3

Slide 3 text

Austin, TX

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

#soloselfie

Slide 8

Slide 8 text

#rubykaraoke

Slide 9

Slide 9 text

@aspleenic

Slide 10

Slide 10 text

#rubykaraoke details 10pm Tonight (after the after party) K BOX @ Chinatown $38++ pax 211 New Bridge Road #04-01 Lucky Chinatown Singapore 059432

Slide 11

Slide 11 text

Red Dot Ruby Conference in Review

Slide 12

Slide 12 text

10 Years of Ruby SG

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

I'll just use this regular expression: /[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)/

Slide 16

Slide 16 text

Ruby has many secrets. #1: Predefined Variables #2: ?, => "," #3: [1,2,3]*? => "1,2,3" #4: "Hello"[/[A-Z]/] => "H"

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

The "fish" in our industry is the ability to think abstractly and knowing what to do when the abstraction eventually leaks.

Slide 19

Slide 19 text

Probably your API is fast enough

Slide 20

Slide 20 text

Google Lies. People don't leave because of managers

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

If there are no tests, there'd be no slow tests

Slide 23

Slide 23 text

Future authorization systems should be less dependent on the developer and give more power to the users

Slide 24

Slide 24 text

A change positive architecture provides maintainable, sustainable, and joyful development

Slide 25

Slide 25 text

Always Be Simulating

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Daru

Slide 28

Slide 28 text

Currencies are tricky. Salaries

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

IoT makes a lot of sense

Slide 31

Slide 31 text

An existing system being used reflects its real needs.

Slide 32

Slide 32 text

Three years on a cold stone will make the stone warm

Slide 33

Slide 33 text

Don't believe in Stars

Slide 34

Slide 34 text

explainshell.com

Slide 35

Slide 35 text

Declarative Paradigms can make it easier to reason about your app

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Regular Expressions: Now you have two problems

Slide 38

Slide 38 text

My Ruby Story

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Started Learning Ruby in 2006

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

After 10 years, Why Ruby?

Slide 45

Slide 45 text

Community

Slide 46

Slide 46 text

Other Languages

Slide 47

Slide 47 text

Ruby isn't cool anymore

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Mature Ecosystem

Slide 50

Slide 50 text

"Bro, I wrote a script in Ruby Today. It felt freeing." -Yehuda Katz

Slide 51

Slide 51 text

Edges of Ruby

Slide 52

Slide 52 text

Fast is a feature

Slide 53

Slide 53 text

Ruby 3x3

Slide 54

Slide 54 text

Ruby 10% Year over Year

Slide 55

Slide 55 text

Thanks Ruby Core Team, AppFolio, Heroku <3

Slide 56

Slide 56 text

"[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/

Slide 57

Slide 57 text

Node.js is great at building efficient web services with lots of I/O

Slide 58

Slide 58 text

ratpack.io

Slide 59

Slide 59 text

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.

Slide 60

Slide 60 text

What's "reactive" actually mean?

Slide 61

Slide 61 text

applying backpressure from a client non-blocking communication

Slide 62

Slide 62 text

non-blocking communication

Slide 63

Slide 63 text

By leveraging powerful concurrency libraries from the JVM, ratpack is built from the ground up to support non-blocking IO.

Slide 64

Slide 64 text

ratpack hello world RatpackServer.start do |b| b.handlers do |chain| chain.get do |ctx| ctx.render("Hello World!") end end end

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

Faban Benchmarks

Slide 68

Slide 68 text

Learn more: hrku.co/jrubrat

Slide 69

Slide 69 text

CPU Bound

Slide 70

Slide 70 text

In 5 samples, ActiveSupport#blank? makes up 3.88% of total CPU time github.com/rails/rails/pull/9958

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

CPU Bound -> Native Extensions

Slide 73

Slide 73 text

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; }

Slide 74

Slide 74 text

Up to 20X faster 5% improvement on macro benchmarks

Slide 75

Slide 75 text

Becoming good at writing safe C is hard

Slide 76

Slide 76 text

issues even for seasoned maintainers C Extensions are Hard

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.

Slide 79

Slide 79 text

If you have successfully compiled a Rust program, it will not segfault at runtime.

Slide 80

Slide 80 text

Zero-Cost Abstractions blog.rust-lang.org/2015/05/11/traits.html

Slide 81

Slide 81 text

blank.rs pub extern "C" fn fast_blank(buf: Buf) -> bool { buf.as_slice().chars().all(|c| c.is_whitespace()) }

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

helix

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

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.

Slide 87

Slide 87 text

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()) } } }

Slide 88

Slide 88 text

TurboRails?

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

Packaging in Ruby

Slide 91

Slide 91 text

story of the heroku toolbelt

Slide 92

Slide 92 text

gem install heroku

Slide 93

Slide 93 text

Requires Ruby to be installed

Slide 94

Slide 94 text

Can't guarantee same version of ruby locally

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

Packaging was a nightmare

Slide 97

Slide 97 text

hk

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

require in ruby is slow

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No Great Packaging Story in Ruby

Slide 103

Slide 103 text

mruby-cli

Slide 104

Slide 104 text

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.

Slide 105

Slide 105 text

writing in ruby

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

fast is a feature

Slide 108

Slide 108 text

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

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

No require

Slide 112

Slide 112 text

a single binary for every major platform

Slide 113

Slide 113 text

docker-compose run compile Linux OS X Windows

Slide 114

Slide 114 text

Size Matters $ ls -nlh mruby-cli | awk '{print $5}' 421K

Slide 115

Slide 115 text

simple setup

Slide 116

Slide 116 text

Docker FROM hone/mruby-cli

Slide 117

Slide 117 text

Hello World Example $ mruby-cli --setup hello

Slide 118

Slide 118 text

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

Slide 119

Slide 119 text

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

Slide 120

Slide 120 text

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

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

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

Slide 123

Slide 123 text

edit mrblib/hello.rb # mrblib/hello.rb def __main__(argv) puts "Hello World" end

Slide 124

Slide 124 text

Learn more: mruby-cli.org

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

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

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

Let's keep writing the Ruby we love without the fear we'll hit a wall.

Slide 129

Slide 129 text

Thank You Red Dot Ruby @hone02