Slide 1

Slide 1 text

Ru b y A l t e r n at i v e s

Slide 2

Slide 2 text

M o o re ’s L a w

Slide 3

Slide 3 text

E v e r y t w o y e a r s

Slide 4

Slide 4 text

E v e r y t w o y e a r s 2 t i m e s f a s t e r

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

W h a ?

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

T h e # $ @ & % * ! G I L

Slide 11

Slide 11 text

– M AT Z , T H I S M O R N I N G “Thread is too hard”

Slide 12

Slide 12 text

We ’ re l i v i n g i n a p o s t M o o re w o r l d

Slide 13

Slide 13 text

– M AT Z , T H I S M O R N I N G “[Ruby 3 will be finished] hopefully within this decade”

Slide 14

Slide 14 text

Hey Aaron! What did you think of Matz’ keynote?

Slide 15

Slide 15 text

(╯°□°)╯︵ ┻━┻ I’M SWITCHING TO ELIXIR!!!!

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

– S E R D A R D O G R U Y O L “Nobody should only learn one programming language”

Slide 18

Slide 18 text

Go

Slide 19

Slide 19 text

Go

Slide 20

Slide 20 text

Go

Slide 21

Slide 21 text

W h i r l w i n d To u r J u s t t o s h ow t h e s e l a n g u a g e s a re n ’ t s c a r y

Slide 22

Slide 22 text

@mraaroncruz

Slide 23

Slide 23 text

@mraaroncruz ROSSConf

Slide 24

Slide 24 text

@mraaroncruz I help startups get and keep users ROSSConf

Slide 25

Slide 25 text

@mraaroncruz ROSSConf Indian Food Chef I help startups get and keep users

Slide 26

Slide 26 text

G o l a n g

Slide 27

Slide 27 text

(Did not sponsor this slide)

Slide 28

Slide 28 text

Pro b l e m s A t G o o g l e

Slide 29

Slide 29 text

Pro b l e m s A t G o o g l e • developer productivity

Slide 30

Slide 30 text

• developer productivity • header files are inefficient Pro b l e m s A t G o o g l e

Slide 31

Slide 31 text

• developer productivity • header files are inefficient • classic type systems (C++, Java) are cumbersome and pushing people toward dynamic languages Pro b l e m s A t G o o g l e

Slide 32

Slide 32 text

• developer productivity • header files are inefficient • classic type systems (C++, Java) are cumbersome and pushing people toward dynamic languages • garbage collection not supported by most systems languages Pro b l e m s A t G o o g l e

Slide 33

Slide 33 text

• developer productivity • header files are inefficient • classic type systems (C++, Java) are cumbersome and pushing people toward dynamic languages • garbage collection not supported by most systems languages • multicore computers on the rise Pro b l e m s A t G o o g l e

Slide 34

Slide 34 text

Fe at u re s O f G o

Slide 35

Slide 35 text

Fe at u re s O f G o • incredibly fast compilation

Slide 36

Slide 36 text

Fe at u re s O f G o • incredibly fast compilation • dependency model simplified

Slide 37

Slide 37 text

Fe at u re s O f G o • incredibly fast compilation • dependency model simplified • light weight static type system

Slide 38

Slide 38 text

Fe at u re s O f G o • incredibly fast compilation • dependency model simplified • light weight static type system • garbage collector

Slide 39

Slide 39 text

Fe at u re s O f G o • incredibly fast compilation • dependency model simplified • light weight static type system • garbage collector • multicore first

Slide 40

Slide 40 text

G o a n d O O P

Slide 41

Slide 41 text

• encapsulation (lower/uppercase) G o a n d O O P

Slide 42

Slide 42 text

• encapsulation (lower/uppercase) • this/self from first argument G o a n d O O P

Slide 43

Slide 43 text

• encapsulation (lower/uppercase) • this/self from first argument • constructor G o a n d O O P

Slide 44

Slide 44 text

• encapsulation (lower/uppercase) • this/self from first argument • constructor • methods G o a n d O O P

Slide 45

Slide 45 text

• encapsulation (lower/uppercase) • this/self from first argument • constructor • methods • mixins G o a n d O O P

Slide 46

Slide 46 text

• encapsulation (lower/uppercase) • this/self from first argument • constructor • methods • mixins • interfaces G o a n d O O P

Slide 47

Slide 47 text

S t r u c t s a n d M e t h o d s

Slide 48

Slide 48 text

type Rubyist struct { Name string FavoriteGems []string }

Slide 49

Slide 49 text

func (r Rubyist) TellMeAboutYourself() { fmt.Printf("Hi. My name is %s and I love %s!\n", r.Name, strings.Join(r.FavoriteGems, ", ")) }

Slide 50

Slide 50 text

func (r Rubyist) TellMeAboutYourself() { fmt.Printf("Hi. My name is %s and I love %s!\n", r.Name, strings.Join(r.FavoriteGems, ", ")) }

Slide 51

Slide 51 text

func (r Rubyist) TellMeAboutYourself() { fmt.Printf("Hi. My name is %s and I love %s!\n", r.Name, strings.Join(r.FavoriteGems, ", ")) }

Slide 52

Slide 52 text

func (r Rubyist) TellMeAboutYourself() { fmt.Printf("Hi. My name is %s and I love %s!\n", r.Name, strings.Join(r.FavoriteGems, ", ")) }

Slide 53

Slide 53 text

func (r Rubyist) TellMeAboutYourself() { fmt.Printf("Hi. My name is %s and I love %s!\n", r.Name, strings.Join(r.FavoriteGems, ", ")) }

Slide 54

Slide 54 text

func main() { gems := []string{"pry", "faraday", "sequel"} aaron := Rubyist{Name: "Aaron", FavoriteGems: gems} aaron.TellMeAboutYourself() }

Slide 55

Slide 55 text

G o ’s Co n c u r re n c y Patt e r n s

Slide 56

Slide 56 text

G o ’s Co n c u r re n c y Patt e r n s • goroutines

Slide 57

Slide 57 text

G o ’s Co n c u r re n c y Patt e r n s • goroutines • channels

Slide 58

Slide 58 text

func main() { messages := make(chan string) go func() { time.Sleep(time.Second * 1) messages <- "ping" }() fmt.Println("Blocking on channel") msg := <-messages fmt.Println(msg) }

Slide 59

Slide 59 text

func main() { messages := make(chan string) go func() { time.Sleep(time.Second * 1) messages <- "ping" }() fmt.Println("Blocking on channel") msg := <-messages fmt.Println(msg) }

Slide 60

Slide 60 text

func main() { messages := make(chan string) go func() { time.Sleep(time.Second * 1) messages <- "ping" }() fmt.Println("Blocking on channel") msg := <-messages fmt.Println(msg) }

Slide 61

Slide 61 text

func main() { messages := make(chan string) go func() { time.Sleep(time.Second * 1) messages <- "ping" }() fmt.Println("Blocking on channel") msg := <-messages fmt.Println(msg) }

Slide 62

Slide 62 text

func main() { messages := make(chan string) go func() { time.Sleep(time.Second * 1) messages <- "ping" }() fmt.Println("Blocking on channel") msg := <-messages fmt.Println(msg) }

Slide 63

Slide 63 text

func main() { messages := make(chan string) go func() { time.Sleep(time.Second * 1) messages <- "ping" }() fmt.Println("Blocking on channel") msg := <-messages fmt.Println(msg) }

Slide 64

Slide 64 text

P r a c t i c a l U s e C a s e

Slide 65

Slide 65 text

P r a c t i c a l U s e C a s e S i d e k i q w o r k e r s

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

func transcode(message *workers.Msg) { // you have access to // create a map of the args from the worker call payload := message.Args().Map() // Transcode it with your transcode package transcoder.Transcode(payload["path"].(string)) }

Slide 68

Slide 68 text

func sendMail(message *workers.Msg) { payload := message.Args().Map() mailerType := payload["mailer"].(string) // Factory function // Infers type and returns interface: Send(string) client := mailer.NewMailer(mailerType) client.Send(payload["email_address"].(string)) }

Slide 69

Slide 69 text

func main() { workers.Configure(map[string]string{ // location of redis instance "server": "localhost:6379", // instance of the database "database": "0", // number of connections to keep open with redis "pool": "30", // unique process id for this instance of workers // (for proper recovery of inprogress jobs on crash) "process": "1", }) 
 //… continued in next slide }

Slide 70

Slide 70 text

func main() { // pull messages from "sendMail" with concurrency of 10 workers.Process("emails", sendMail, 10) // pull messages from "transcode" with concurrency of 20 workers.Process("transcode", transcode, 20) // stats will be available at http://localhost:8080/stats go workers.StatsServer(8080) // Blocks until process is told to exit via unix signal workers.Run() }

Slide 71

Slide 71 text

func main() { // pull messages from "sendMail" with concurrency of 10 workers.Process("emails", sendMail, 10) // pull messages from "transcode" with concurrency of 20 workers.Process("transcode", transcode, 20) // stats will be available at http://localhost:8080/stats go workers.StatsServer(8080) // Blocks until process is told to exit via unix signal workers.Run() }

Slide 72

Slide 72 text

func main() { // pull messages from "sendMail" with concurrency of 10 workers.Process("emails", sendMail, 10) // pull messages from "transcode" with concurrency of 20 workers.Process("transcode", transcode, 20) // stats will be available at http://localhost:8080/stats go workers.StatsServer(8080) // Blocks until process is told to exit via unix signal workers.Run() }

Slide 73

Slide 73 text

func main() { // pull messages from "sendMail" with concurrency of 10 workers.Process("emails", sendMail, 10) // pull messages from "transcode" with concurrency of 20 workers.Process("transcode", transcode, 20) // stats will be available at http://localhost:8080/stats go workers.StatsServer(8080) // Blocks until process is told to exit via unix signal workers.Run() }

Slide 74

Slide 74 text

func main() { // pull messages from "sendMail" with concurrency of 10 workers.Process("emails", sendMail, 10) // pull messages from "transcode" with concurrency of 20 workers.Process("transcode", transcode, 20) // stats will be available at http://localhost:8080/stats go workers.StatsServer(8080) // Blocks until process is told to exit via unix signal workers.Run() }

Slide 75

Slide 75 text

I G o

Slide 76

Slide 76 text

I G o

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

E l i x i r ’s Fe at u re s

Slide 83

Slide 83 text

E l i x i r ’s Fe at u re s • functional

Slide 84

Slide 84 text

E l i x i r ’s Fe at u re s • functional • concurrency up front

Slide 85

Slide 85 text

E l i x i r ’s Fe at u re s • functional • concurrency up front • fault tolerant (supervisor tree)

Slide 86

Slide 86 text

E l i x i r ’s Fe at u re s • functional • concurrency up front • fault tolerant (supervisor tree) • REPL

Slide 87

Slide 87 text

E l i x i r ’s Fe at u re s • functional • concurrency up front • fault tolerant (supervisor tree) • REPL • great standard library

Slide 88

Slide 88 text

E l i x i r ’s Fe at u re s • functional • concurrency up front • fault tolerant (supervisor tree) • REPL • great standard library • metaprogramming

Slide 89

Slide 89 text

E l i x i r ’s Fe at u re s • functional • concurrency up front • fault tolerant (supervisor tree) • REPL • great standard library • metaprogramming • macros

Slide 90

Slide 90 text

E l i x i r ’s Fe at u re s • functional • concurrency up front • fault tolerant (supervisor tree) • REPL • great standard library • metaprogramming • macros • tooling

Slide 91

Slide 91 text

f u n c t i o n a l i m m u t a b l e d a t a

Slide 92

Slide 92 text

– M AT Z , T H I S M O R N I N G “Shared state is the source of all evil!”

Slide 93

Slide 93 text

c o n c u r re n c y f i r s t a c t o r p a t t e r n

Slide 94

Slide 94 text

1 1 1 1 1 1 1 1

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

f a u l t t o l e r a n t s u p e r v i s o r t re e

Slide 97

Slide 97 text

M o d u l e s

Slide 98

Slide 98 text

defmodule SumsTheThings do def sum(a, b) do do_sum(a, b) end defp do_sum(a, b) do a + b end end SumsTheThings.sum(1, 2) #=> 3

Slide 99

Slide 99 text

defmodule User do defstruct username: nil, email: nil, login_attempts: 0 end aaron = %User{ username: “pferdefleisch", email: "[email protected]" }

Slide 100

Slide 100 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 101

Slide 101 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 102

Slide 102 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 103

Slide 103 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 104

Slide 104 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 105

Slide 105 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 106

Slide 106 text

defmodule Shape do def area({:rectangle, w, h}) do w * h end def area({:circle, r}) do :math.pi * r * r end end Shape.area({:rectangle, 2, 3}) #=> 6 Shape.area({:circle, 3}) #=> 28.25999999999999801048 Shape.area({:circle, 3, 2}) #=> no function clause matching in Shape.area/1 # examples adopted from learnxinyminutes.com

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

f a s t c o n c u r re n t b e a u t i f u l re l i a b l e

Slide 109

Slide 109 text

T h e R o u t e r

Slide 110

Slide 110 text

defmodule HelloPhoenix.Router do use HelloPhoenix.Web, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :api do plug :accepts, ["json"] end scope "/", HelloPhoenix do pipe_through :browser # Use the default browser stack get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", HelloPhoenix do # pipe_through :api # end end

Slide 111

Slide 111 text

defmodule HelloPhoenix.Router do use HelloPhoenix.Web, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :api do plug :accepts, ["json"] end scope "/", HelloPhoenix do pipe_through :browser # Use the default browser stack get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", HelloPhoenix do # pipe_through :api # end end

Slide 112

Slide 112 text

defmodule HelloPhoenix.Router do use HelloPhoenix.Web, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :api do plug :accepts, ["json"] end scope "/", HelloPhoenix do pipe_through :browser # Use the default browser stack get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", HelloPhoenix do # pipe_through :api # end end

Slide 113

Slide 113 text

defmodule HelloPhoenix.Router do use HelloPhoenix.Web, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :api do plug :accepts, ["json"] end scope "/", HelloPhoenix do pipe_through :browser # Use the default browser stack get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", HelloPhoenix do # pipe_through :api # end end

Slide 114

Slide 114 text

defmodule HelloPhoenix.Router do use HelloPhoenix.Web, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :api do plug :accepts, ["json"] end scope "/", HelloPhoenix do pipe_through :browser # Use the default browser stack get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", HelloPhoenix do # pipe_through :api # end end

Slide 115

Slide 115 text

T h e C o n t ro l l e r

Slide 116

Slide 116 text

defmodule HelloPhoenix.PageController do use HelloPhoenix.Web, :controller def index(conn, _params) do render conn, "index.html" end end

Slide 117

Slide 117 text

defmodule HelloPhoenix.UsersController do use HelloPhoenix.Web, :controller def show(conn, %{"product_id" => product_id}) do product = Repo.get(Product, product_id) render conn, "show.html", product: product end end

Slide 118

Slide 118 text

defmodule HelloPhoenix.UsersController do use HelloPhoenix.Web, :controller def show(conn, %{"product_id" => product_id}) do product = Repo.get(Product, product_id) render conn, "show.html", product: product end end

Slide 119

Slide 119 text

defmodule HelloPhoenix.UsersController do use HelloPhoenix.Web, :controller def show(conn, %{"product_id" => product_id}) do product = Repo.get(Product, product_id) render conn, "show.html", product: product end end

Slide 120

Slide 120 text

defmodule HelloPhoenix.UsersController do use HelloPhoenix.Web, :controller def show(conn, %{"product_id" => product_id}) do product = Repo.get(Product, product_id) render conn, "show.html", product: product end end

Slide 121

Slide 121 text

S t u ff I D i d n ’ t H a v e Ti m e Fo r

Slide 122

Slide 122 text

S t u ff I D i d n ’ t H a v e Ti m e Fo r • concurrency model

Slide 123

Slide 123 text

S t u ff I D i d n ’ t H a v e Ti m e Fo r • concurrency model • text processing

Slide 124

Slide 124 text

S t u ff I D i d n ’ t H a v e Ti m e Fo r • concurrency model • text processing • metaprogramming

Slide 125

Slide 125 text

S t u ff I D i d n ’ t H a v e Ti m e Fo r • concurrency model • text processing • metaprogramming • error handling

Slide 126

Slide 126 text

S t u ff I D i d n ’ t H a v e Ti m e Fo r • concurrency model • text processing • metaprogramming • error handling • macros

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

S o m e Pro b l e m s W i t h Ru b y

Slide 130

Slide 130 text

S o m e Pro b l e m s W i t h Ru b y • performance

Slide 131

Slide 131 text

S o m e Pro b l e m s W i t h Ru b y • performance • most of errors happen at runtime

Slide 132

Slide 132 text

S o m e Pro b l e m s W i t h Ru b y • performance • most of errors happen at runtime • large memory footprint

Slide 133

Slide 133 text

C r y s t a l ’s G o a l s

Slide 134

Slide 134 text

C r y s t a l ’s G o a l s • Have the same syntax as Ruby, or at least as similar as possible.

Slide 135

Slide 135 text

C r y s t a l ’s G o a l s • Have the same syntax as Ruby, or at least as similar as possible. • Never have to specify the type of a variable or method argument.

Slide 136

Slide 136 text

C r y s t a l ’s G o a l s • Have the same syntax as Ruby, or at least as similar as possible. • Never have to specify the type of a variable or method argument. • Be able to call C code by writing bindings to it in Crystal.

Slide 137

Slide 137 text

C r y s t a l ’s G o a l s • Have the same syntax as Ruby, or at least as similar as possible. • Never have to specify the type of a variable or method argument. • Be able to call C code by writing bindings to it in Crystal. • Have compile-time evaluation and generation of code, to avoid boilerplate code.

Slide 138

Slide 138 text

C r y s t a l ’s G o a l s • Have the same syntax as Ruby, or at least as similar as possible. • Never have to specify the type of a variable or method argument. • Be able to call C code by writing bindings to it in Crystal. • Have compile-time evaluation and generation of code, to avoid boilerplate code. • Compile to efficient native code.

Slide 139

Slide 139 text

S o m e O f C r y s t a l ’s Fe at u re s

Slide 140

Slide 140 text

S o m e O f C r y s t a l ’s Fe at u re s • method overloading

Slide 141

Slide 141 text

S o m e O f C r y s t a l ’s Fe at u re s • method overloading • concurrency via channels and spawn

Slide 142

Slide 142 text

S o m e O f C r y s t a l ’s Fe at u re s • method overloading • concurrency via channels and spawn • static typing with type inference

Slide 143

Slide 143 text

S o m e O f C r y s t a l ’s Fe at u re s • method overloading • concurrency via channels and spawn • static typing with type inference • FFI-like simple C bindings

Slide 144

Slide 144 text

class User def initialize(name) @name = name end def say_my_name puts "My name is #{@name}" end end user = User.new("Aaron") user.say_my_name

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

K e m a l

Slide 147

Slide 147 text

require "kemal" messages = [] of String sockets = [] of HTTP::WebSocket public_folder "src/assets" get "/" do render "src/views/index.ecr" end ws "/" do |socket| sockets.push socket socket.on_message do |message| messages.push message sockets.each do |a_socket| a_socket.send messages.to_json end end end

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

So Easy With Crystal :+1:

Slide 150

Slide 150 text

No content

Slide 151

Slide 151 text

M D T C A S W D T C

Slide 152

Slide 152 text

M D T C A S W D T C

Slide 153

Slide 153 text

I R u b y

Slide 154

Slide 154 text

I R u b y

Slide 155

Slide 155 text

exercism.io

Slide 156

Slide 156 text

T h a n k Yo u b i t . l y / r u b y - a l t e r n a t i v e s @mraaroncruz S l i d e s a n d re s o u rc e s a t :