Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

palkan_tula palkan Why is Ruby impressive? 2 ͳͥRuby͸͍͢͝ͷ͔

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

palkan_tula palkan h = {x:, y:} def foo(&) bar(&) 5 2015 2018 2019 2020 2021 2022 2024 1... &. ...1 case ... in def x = 1 def foo(*) bar(*) 1 in x proc { it } def foo(...) proc { _1 }

Slide 6

Slide 6 text

palkan_tula palkan 6 2024 2025 2026 2027 2028 2029 2030 proc { it } ?? ?? ?? ?? ?? ??

Slide 7

Slide 7 text

palkan_tula palkan –D. Crystal “The only languages which do not change are dead ones” 7 มΘΒͳ͍ݴޠ͸ࢮΜͩݴޠͰ͢ɻ

Slide 8

Slide 8 text

palkan_tula palkan 8 2024 2025 2026 2027 2028 2029 2030 proc { it } ?? ?? ?? ?? ?? ??

Slide 9

Slide 9 text

palkan_tula palkan 8 2024 2025 2026 2027 2028 2029 2030 proc { it } ?? ??

Slide 10

Slide 10 text

palkan_tula palkan 15 2013 2015 2017 2019 2020 2021 &. proc { it } 2024 proc { it } &. h = {x:, y:} case ... in case ... in h = {x:, y:} def x = 1 def x = 1

Slide 11

Slide 11 text

palkan_tula palkan Adding new syntax is irreversible 16 ৽͍͠จ๏Λಋೖ͢Δͱޙ໭ΓͰ͖ͳ͍

Slide 12

Slide 12 text

palkan_tula palkan How to predict new syntax benefits? 17 ৽͍͠จ๏ͷϝϦοτΛͲ͏༧ଌ͢Δ͔

Slide 13

Slide 13 text

palkan_tula palkan I. Encourage early adopters to experiment with proposals. 18 ΞʔϦʔΞμϓλʔʹ৽نఏҊͰ࣮ݧͯ͠΋Β͏

Slide 14

Slide 14 text

palkan_tula palkan 19

Slide 15

Slide 15 text

20

Slide 16

Slide 16 text

21

Slide 17

Slide 17 text

23

Slide 18

Slide 18 text

24

Slide 19

Slide 19 text

25

Slide 20

Slide 20 text

RubyKaigi

Slide 21

Slide 21 text

RubyWasmKaigi

Slide 22

Slide 22 text

28 github.com/palkan

Slide 23

Slide 23 text

29 evilmartians.com

Slide 24

Slide 24 text

30 urlgeni.us/amazon/Rails-book

Slide 25

Slide 25 text

LET'S START MIXING ʮ࢝ΊΑ͏ʂʯ

Slide 26

Slide 26 text

palkan_tula palkan I. Encourage early adopters to experiment with proposals. 32 ΞʔϦʔΞμϓλʔʹ৽نఏҊͰ࣮ݧͯ͠΋Β͏

Slide 27

Slide 27 text

palkan_tula palkan I. Encourage early adopters to experiment with proposals. II. Learn from other languages. 32 ΞʔϦʔΞμϓλʔʹ৽نఏҊͰ࣮ݧͯ͠΋Β͏ ଞͷݴޠΛࢀߟʹ͢Δ

Slide 28

Slide 28 text

palkan_tula palkan h = {x:, y:} 33

Slide 29

Slide 29 text

palkan_tula palkan h = {x:, y:} 33

Slide 30

Slide 30 text

palkan_tula palkan h = {x:, y:} 33

Slide 31

Slide 31 text

palkan_tula palkan 1

Slide 32

Slide 32 text

35

Slide 33

Slide 33 text

2

Slide 34

Slide 34 text

palkan_tula palkan user["name"] = user["name"] ?: "Guest" 36 PHP: $user['name'] ??= 'Guest' Kotlin: JavaScript: user.name ??= 'guest' Elvis operator

Slide 35

Slide 35 text

palkan_tula palkan 37

Slide 36

Slide 36 text

palkan_tula palkan ! → " SyntaxError Use cases Implementation 38 ࣮૷ Ϣʔεέʔε

Slide 37

Slide 37 text

palkan_tula palkan ?= 39

Slide 38

Slide 38 text

palkan_tula palkan $ 40 ruby -e 'a ?= 1' -e:1: syntax error, unexpected integer literal, expecting end-of-input a ?= 1 -e: compile error (SyntaxError)

Slide 39

Slide 39 text

palkan_tula palkan ?= a = nil a ?= false # a is false a ?= 1 # a is false a ||= 1 # a is 1 41

Slide 40

Slide 40 text

42

Slide 41

Slide 41 text

palkan_tula palkan Use cases I. (a = false) ?= 2024 #=> false ... 43 Ϣʔεέʔε

Slide 42

Slide 42 text

palkan_tula palkan 44

Slide 43

Slide 43 text

palkan_tula palkan 45

Slide 44

Slide 44 text

46

Slide 45

Slide 45 text

palkan_tula palkan ?= ❤ Hash h = {val: nil} # h[:val] = 42 unless h.key?(:val) h[:val] ?= 42 h #=> {val: nil} 47

Slide 46

Slide 46 text

palkan_tula palkan ?= ❤ @var def current_user return @current_user if defined?(@current_user) @current_user = find_user end 48

Slide 47

Slide 47 text

palkan_tula palkan def current_user @current_user ?= find_user end 49 def current_user return @current_user if defined?(@current_user) @current_user = find_user end ?= ❤ @var

Slide 48

Slide 48 text

50

Slide 49

Slide 49 text

palkan_tula palkan def current_user @current_user ?= find_user end 51 def current_user return @current_user if defined?(@current_user) @current_user = find_user end ?= ❤ @var

Slide 50

Slide 50 text

palkan_tula palkan ΦϒδΣΫτγΣΠϓ def current_user @current_user ?= find_user end 51 def current_user return @current_user if defined?(@current_user) @current_user = find_user end $ Object shapes :( ?= ❤ @var

Slide 51

Slide 51 text

52

Slide 52

Slide 52 text

palkan_tula palkan I. (a = false) ?= 2024 #=> false 53 Use cases Ϣʔεέʔε

Slide 53

Slide 53 text

palkan_tula palkan I. (a = false) ?= 2024 #=> false II. h[:x] ?= 5 53 Use cases Ϣʔεέʔε

Slide 54

Slide 54 text

palkan_tula palkan I. (a = false) ?= 2024 #=> false II. h[:x] ?= 5 III. @value ?= maybe_some 53 Use cases Ϣʔεέʔε

Slide 55

Slide 55 text

palkan_tula palkan εϚʔτΦϒδΣΫτγΣΠϓ I. (a = false) ?= 2024 #=> false II. h[:x] ?= 5 III. @value ?= maybe_some ⏳ Smart object shapes 54 Use cases Ϣʔεέʔε

Slide 56

Slide 56 text

palkan_tula palkan ?= → ❤ SyntaxError Use cases Implementation 55 ࣮૷ Ϣʔεέʔε → lexer, parser

Slide 57

Slide 57 text

palkan_tula palkan 3

Slide 58

Slide 58 text

57

Slide 59

Slide 59 text

palkan_tula palkan def beach(*temperature) case temperature in :celcius | :c, (20..45) :favorable in :kelvin | :k, (293..318) :scientifically_favorable in :fahrenheit | :f, (68..113) :favorable_in_us else :avoid_beach end end 58

Slide 60

Slide 60 text

palkan_tula palkan beach(Temperature) -> case Temperature of {celsius, N} when N >= 20, N =< 45 -> 'favorable'; {kelvin, N} when N >= 293, N =< 318 -> 'scientifically favorable'; {fahrenheit, N} when N >= 68, N =< 113 -> 'favorable in the US'; _ -> 'avoid beach' end. 59

Slide 61

Slide 61 text

palkan_tula palkan beach({celsius, N}) when N >= 20, N =< 45 -> 'favorable'; beach({kelvin, N}) when N >= 293, N =< 318 -> 'scientifically favorable'; beach({fahrenheit, N}) when N >= 68, N =< 113 -> 'favorable in the US'; beach(_) -> 'avoid beach'. 60

Slide 62

Slide 62 text

palkan_tula palkan 61

Slide 63

Slide 63 text

palkan_tula palkan 62

Slide 64

Slide 64 text

palkan_tula palkan def beach(*temperature) case temperature in :celcius | :c, (20..45) :favorable in :kelvin | :k, (293..318) :scientifically_favorable in :fahrenheit | :f, (68..113) :favorable_in_us else :avoid_beach end end 63

Slide 65

Slide 65 text

palkan_tula palkan def beach in :celcius | :c, (20..45) :favorable end def beach in :kelvin | :k, (293..318) :scientifically_favorable end def beach in :fahrenheit | :f, (68..113) :favorable_in_us end def beach(...) = :avoid_beach 64

Slide 66

Slide 66 text

palkan_tula palkan $ 65 ruby -e 'def foo in :c, Integer => v; v; end' -e:1: syntax error, unexpected `in', expecting ';' or '\n' def foo in :c, Integer => v; v; end -e: compile error (SyntaxError)

Slide 67

Slide 67 text

palkan_tula palkan def ... in No new keywords Resembles other languages (Elixir, Crystal, etc.) Idiomatic Ruby & 66 ৽͍͠ΩʔϫʔυΛ૿΍͞ͳ͍ ଞͷݴޠʹࣅͤΔ Ruby ͷΠσΟΦϜʹै͏

Slide 68

Slide 68 text

67

Slide 69

Slide 69 text

69

Slide 70

Slide 70 text

palkan_tula palkan foo(*args) — ' 70

Slide 71

Slide 71 text

palkan_tula palkan foo(*args) — ' foo(**kwargs) — ' 70

Slide 72

Slide 72 text

palkan_tula palkan foo(*args) — ' foo(**kwargs) — ' foo(*args, **kwargs) — ( 70

Slide 73

Slide 73 text

palkan_tula palkan foo(*args) — ' foo(**kwargs) — ' foo(*args, **kwargs) — ( def foo in (if | unless) — ( 70

Slide 74

Slide 74 text

palkan_tula palkan foo(*args) — ' foo(**kwargs) — ' foo(*args, **kwargs) — ( def foo in (if | unless) — ( prepend/class_eval/etc. — ' 70

Slide 75

Slide 75 text

71

Slide 76

Slide 76 text

palkan_tula palkan How can we implement this? 72 ͲͷΑ͏ʹ࣮૷͢Ε͹ྑ͍͔ʁ

Slide 77

Slide 77 text

palkan_tula palkan 73 beach(Temperature) -> case Temperature of {celsius, N} when N >= 20, N =< 45 -> 'favorable'; {kelvin, N} when N >= 293, N =< 318 -> 'scientifically favorable'; {fahrenheit, N} when N >= 68, N =< 113 -> 'favorable in the US'; _ -> 'avoid beach' end. beach({celsius, N}) when N >= 20, N =< 45 -> 'favorable'; beach({kelvin, N}) when N >= 293, N =< 318 -> 'scientifically favorable'; beach({fahrenheit, N}) when N >= 68, N =< 113 -> 'favorable in the US'; beach(_) -> 'avoid beach'.

Slide 78

Slide 78 text

palkan_tula palkan ಉ͡όΠτίʔυ Same byte code 74 beach(Temperature) -> case Temperature of {celsius, N} when N >= 20, N =< 45 -> 'favorable'; {kelvin, N} when N >= 293, N =< 318 -> 'scientifically favorable'; {fahrenheit, N} when N >= 68, N =< 113 -> 'favorable in the US'; _ -> 'avoid beach' end. beach({celsius, N}) when N >= 20, N =< 45 -> 'favorable'; beach({kelvin, N}) when N >= 293, N =< 318 -> 'scientifically favorable'; beach({fahrenheit, N}) when N >= 68, N =< 113 -> 'favorable in the US'; beach(_) -> 'avoid beach'.

Slide 79

Slide 79 text

75

Slide 80

Slide 80 text

palkan_tula palkan SyntaxError Use cases Implementation 76 ࣮૷ Ϣʔεέʔε → parser def ... in → ❤

Slide 81

Slide 81 text

palkan_tula palkan 4

Slide 82

Slide 82 text

palkan_tula palkan def initialize(@a, @b) 78

Slide 83

Slide 83 text

palkan_tula palkan def initialize(@a, @b) 78

Slide 84

Slide 84 text

palkan_tula palkan CoffeeScript: define_method(:initialize) {|@a, @b|} 79 def initialize(@a, @b) initialize(@a, @b) -> def initialize(@name : String) Crystal: Ruby <1.9:

Slide 85

Slide 85 text

80

Slide 86

Slide 86 text

81

Slide 87

Slide 87 text

82

Slide 88

Slide 88 text

83

Slide 89

Slide 89 text

palkan_tula palkan SyntaxError Use cases Implementation 84 ࣮૷ Ϣʔεέʔε → parser, VM? def initialize(@a) → ❤

Slide 90

Slide 90 text

palkan_tula palkan Anonymous Struct 85

Slide 91

Slide 91 text

palkan_tula palkan Anonymous Struct 86

Slide 92

Slide 92 text

palkan_tula palkan ෆม Zig: 87 var pt: Point = .{ .x = 3, .y = 4, }; #{ x: 3, y: 4 } JavaScript (proposal): Anonymous Struct Immutable

Slide 93

Slide 93 text

palkan_tula palkan .{x: 3, y: 4} 88

Slide 94

Slide 94 text

89

Slide 95

Slide 95 text

palkan_tula palkan SyntaxError Use cases Implementation 90 ࣮૷ Ϣʔεέʔε → parser, stdlib .{x: 3, y: 4} → ❤

Slide 96

Slide 96 text

palkan_tula palkan 91

Slide 97

Slide 97 text

palkan_tula palkan 92

Slide 98

Slide 98 text

palkan_tula palkan |> 93

Slide 99

Slide 99 text

palkan_tula palkan ॓୊ |> 93 ) Your homework

Slide 100

Slide 100 text

palkan_tula palkan "https://api.github.com/repos/ruby/ruby" .then { URI.parse(it) } .then { Net::HTTP.get(it) } .then { JSON.parse(it).fetch("stargazers_count") } .then { "Ruby has #{it} stars" } .then { Kernel.puts(it) } 94

Slide 101

Slide 101 text

palkan_tula palkan "https://api.github.com/repos/ruby/ruby" |> URI.parse |> Net::HTTP.get |> JSON.parse(it).fetch("stargazers_count") |> "Ruby has #{it} stars" |> Kernel.puts 95

Slide 102

Slide 102 text

palkan_tula palkan Try using proposed syntax in your code Share you examples Report confusions and edge cases 96 ͜ͷจ๏Λࣗ෼ͷίʔυͰࢼͯ͠ΈΔ ॻ͍ͨίʔυΛڞ༗͢Δ ͏·͍͔͘ͳ͍ྫ΍ΤοδέʔεΛใࠂ

Slide 103

Slide 103 text

97

Slide 104

Slide 104 text

palkan_tula palkan 98 bit.ly/ruby-mixology

Slide 105

Slide 105 text

Thank You Slides: evilmartians.com/events Twitter: @palkan_tula, @evilmartians ͋Γ͕ͱ͏