Next Ruby. Crafting a new ideal language with DSL and ruby-next

A presentation at Saint P Ruby Summer Meetup in August 2021 in St Petersburg, Russia by Svyatoslav Kryukov

Slide 1

Slide 1

Next Ruby Crafting a new ideal language with DSL and ruby-next

Slide 2

Slide 2

Ruby dev team goals • Performance (JIT) • Concurrency (Ractors) • Typing (RBS)

Slide 3

Slide 3

? ? ?

Slide 4

Slide 4

Slide 5

Slide 5

HR inbox

Slide 6

Slide 6

Slide 7

Slide 7

Are you ready to drop Ruby?

Slide 8

Slide 8

Are you ready to drop Ruby? Results YES NO 146% 0%

Slide 9

Slide 9

Wait a minute Who are you?

Slide 10

Slide 10

What’s next?

Slide 11

Slide 11

How to move away from Ruby? • Complete rewrite • Microservices • Perfect solution, silver bullet…

Slide 12

Slide 12

Let’s write Go

Slide 13

Slide 13

Let’s write Go in Ruby!

Slide 14

Slide 14

A Tour of Go: Hello World

Slide 15

Slide 15

Slide 16

Slide 16

Slide 17

Slide 17

Slide 18

Slide 18

Slide 19

Slide 19

Slide 20

Slide 20

Go package Functions, types, variables, and constants are visible to all source files within the same package

Slide 21

Slide 21

Go package Functions, types, variables, and constants are visible to all source files within the same package Feels like a Ruby Module

Slide 22

Slide 22

Slide 23

Slide 23

Slide 24

Slide 24

Slide 25

Slide 25

Slide 26

Slide 26

Slide 27

Slide 27

Slide 28

Slide 28

Slide 29

Slide 29

One method_missing to rule them all

Slide 30

Slide 30

Slide 31

Slide 31

Slide 32

Slide 32

Slide 33

Slide 33

Slide 34

Slide 34

Slide 35

Slide 35

Go, Ruby, Go!

Slide 36

Slide 36

Slide 37

Slide 37

Slide 38

Slide 38

Go, Ruby, Go!

Slide 39

Slide 39

Slide 40

Slide 40

= :

Slide 41

Slide 41

Slide 42

Slide 42

Slide 43

Slide 43

a “Hello, 世界” Lexer [tIDENTIFIER, “a”], [tCOLON, “:”], [tEQL, “=”], [tSTRING, “Hello, 世界”] Parser

: SyntaxError

Slide 44

Slide 44

How to fix this? • Ask the Core team to add := • Fork Ruby • Juggle AST like it’s 1999

Slide 45

Slide 45

Coming up next, ruby-next

Slide 46

Slide 46

a “Hello, 世界” Lexer [tIDENTIFIER, “a”], [tGOEQL, ” “], [tSTRING, “Hello, 世界”] Parser

:

: (lvasgn :a (str “Hello, 世界”))

Slide 47

Slide 47

a “Hello, 世界” Lexer [tIDENTIFIER, “a”], [tGOEQL, ” “], [tSTRING, “Hello, 世界”] Parser (lvasgn :a (str “Hello, 世界”))

:

: gem “parser”

Slide 48

Slide 48

a “Hello, 世界” Ragel Lexer [tIDENTIFIER, “a”], [tGOEQL, ” “], [tSTRING, “Hello, 世界”] Parser (lvasgn :a (str “Hello, 世界”))

:

: gem “parser”

Slide 49

Slide 49

Serious Shchi

Slide 50

Slide 50

Ragel State Machine Compiler • Finite-state machine compiler and a parser generator. • Works with a lot of languages (C, C++, Java, Go, Ruby, etc.)

Slide 51

Slide 51

Slide 52

Slide 52

Slide 53

Slide 53

Slide 54

Slide 54

Slide 55

Slide 55

Slide 56

Slide 56

Slide 57

Slide 57

Slide 58

Slide 58

2 + 2 Lexer [tNUMBER, 2], [tPLUS, “+”], [tNUMBER, 2]

Slide 59

Slide 59

Slide 60

Slide 60

Slide 61

Slide 61

Slide 62

Slide 62

Slide 63

Slide 63

Slide 64

Slide 64

Slide 65

Slide 65

Slide 66

Slide 66

Slide 67

Slide 67

Slide 68

Slide 68

Slide 69

Slide 69

Slide 70

Slide 70

Slide 71

Slide 71

Slide 72

Slide 72

Slide 73

Slide 73

Slide 74

Slide 74

Slide 75

Slide 75

a “Hello, 世界” Ragel Lexer [tIDENTIFIER, “a”], [tGOEQL, ” “], [tSTRING, “Hello, 世界”] Parser (lvasgn :a (str “Hello, 世界”))

:

: gem “parser”

Slide 76

Slide 76

Slide 77

Slide 77

a “Hello, 世界” Ragel Lexer [tIDENTIFIER, “a”], [tGOEQL, ” “], [tSTRING, “Hello, 世界”] Racc Parser (lvasgn :a (str “Hello, 世界”))

:

: gem “parser”

Slide 78

Slide 78

Rake Rack Racc • Yacc/Bison like parser generator • Grammar le should contain: • parser class with de ned #next_token fi fi • rules block

Slide 79

Slide 79

[tNUMBER, 2], [tPLUS, “+”], [tNUMBER, 2] Parser [:send, [:number, 2], :+, [:number, 2]]

Slide 80

Slide 80

Lexer Parser

Slide 81

Slide 81

Lexer Parser “2 + (1 + 7) * 5”

Slide 82

Slide 82

Slide 83

Slide 83

Slide 84

Slide 84

Slide 85

Slide 85

Slide 86

Slide 86

Slide 87

Slide 87

Slide 88

Slide 88

Slide 89

Slide 89

Slide 90

Slide 90

Slide 91

Slide 91

Slide 92

Slide 92

Slide 93

Slide 93

Vin again

Slide 94

Slide 94

a “Hello, 世界” Ragel Lexer [tIDENTIFIER, “a”], [tGOEQL, ” “], [tSTRING, “Hello, 世界”] Racc Parser (lvasgn :a (str “Hello, 世界”))

:

: gem “parser”

Slide 95

Slide 95

Transpiler mode Runtime mode

Slide 96

Slide 96

Slide 97

Slide 97

a “Hello, 世界”

: (lvasgn :a (str “Hello, 世界”))

Slide 98

Slide 98

a “Hello, 世界”

: (lvasgn :a (str “Hello, 世界”)) a = “Hello, 世界” (lvasgn :a (str “Hello, 世界”))

Slide 99

Slide 99

a “Hello, 世界” ^^ tGOEQL ” “

:

: (lvasgn :a (str “Hello, 世界”)) a = “Hello, 世界” ^ tEQL “=” (lvasgn :a (str “Hello, 世界”))

Slide 100

Slide 100

Slide 101

Slide 101

Slide 102

Slide 102

Slide 103

Slide 103

If you give a man a fish…

Slide 104

Slide 104

Slide 105

Slide 105

https://evl.ms/obey

Slide 106

Slide 106

Slide 107

Slide 107

Questions?