×
Copy
Open
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Elixir vs Ruby vs JavaScript Syntax Elixir School Maksym Verbovyi August 2020, Hamburg
Slide 2
Slide 2 text
Disclaimer
Slide 3
Slide 3 text
Basics Tools and common usage
Slide 4
Slide 4 text
Interactive Shell iex irb jsc
Slide 5
Slide 5 text
Run task mix rake npm
Slide 6
Slide 6 text
Dependencies mix bundler npm
Slide 7
Slide 7 text
Debug IEX.pry binding.pry debugger
Slide 8
Slide 8 text
Polymorphism Protocols Polymorphism Extends
Slide 9
Slide 9 text
Metaprogramming Macros Metaprogramming Proxy Reflect
Slide 10
Slide 10 text
Popular framework Phoenix Rails React Vue.js
Slide 11
Slide 11 text
Syntax Be awesome
Slide 12
Slide 12 text
String "String" 'string'
Slide 13
Slide 13 text
String "String" 'string' "String" 'string'
Slide 14
Slide 14 text
String "String" 'Not string' # [110, 111, 116, 32, 115, 116, 114, 105, 110, 103] "String" 'string' "String" 'string'
Slide 15
Slide 15 text
Atom :symbol
Slide 16
Slide 16 text
Atom Symbol('string') :symbol
Slide 17
Slide 17 text
Atom Symbol('string') :symbol :atom
Slide 18
Slide 18 text
Boolean true || false
Slide 19
Slide 19 text
Boolean true || false true || false
Slide 20
Slide 20 text
Boolean true || false true || false true || false
Slide 21
Slide 21 text
List [1, :a, "b", true] *
Slide 22
Slide 22 text
List [1, Symbol('a'), "b", true] * [1, :a, "b", true] *
Slide 23
Slide 23 text
List [1, :a, "b", true] [1, Symbol('a'), "b", true] * [1, :a, "b", true] *
Slide 24
Slide 24 text
Tuple {1, :a, "b", true} [1, Symbol('a'), "b", true] * [1, :a, "b", true] *
Slide 25
Slide 25 text
Map { name: "Maks", age: 32, height: 178 }
Slide 26
Slide 26 text
Map { name: "Maks", age: 32, height: 178 } { name: "Maks", age: 32, height: 178 }
Slide 27
Slide 27 text
Map %{ name: "Maks", age: 32, height: 178 } { name: "Maks", age: 32, height: 178 } { name: "Maks", age: 32, height: 178 }
Slide 28
Slide 28 text
Nil nil
Slide 29
Slide 29 text
Nil nil null
Slide 30
Slide 30 text
Nil nil nil null
Slide 31
Slide 31 text
Interpolation "Hello #{ruby}"
Slide 32
Slide 32 text
Interpolation "Hello #{ruby}" `Hello ${javascript}`
Slide 33
Slide 33 text
Interpolation "Hello #{ruby}" "Hello #{elixir}" `Hello ${javascript}`
Slide 34
Slide 34 text
Concatenation String "Elixir" + "School" "Elixir" << "School" "Elixir".concat("School")
Slide 35
Slide 35 text
Concatenation String "Elixir" + "School" "Elixir" << "School" "Elixir".concat("School") "Elixir" + "School" "Elixir".concat("School")
Slide 36
Slide 36 text
Concatenation String "Elixir" + "School" "Elixir" << "School" "Elixir".concat("School") "Elixir" + "School" "Elixir".concat("School") "Hello" <> "Elixir"
Slide 37
Slide 37 text
Concatenation List [1,2,3] + [4,5] # [1,2,3,4,5] [1,2] << 3 # [1,2,3]
Slide 38
Slide 38 text
Concatenation List [1,2,3] + [4,5] # [1,2,3,4,5] [1,2] << 3 # [1,2,3] [1,2,3].concat([4,5]) // [1,2,3,4,5]
Slide 39
Slide 39 text
Concatenation List [1,2,3] + [4,5] # [1,2,3,4,5] [1,2] << 3 # [1,2,3] [1,2,3].concat([4,5]) // [1,2,3,4,5] [1,2,3] ++ [4,5] # [1,2,3,4,5] [3 | [1,2]] # [3,1,2]
Slide 40
Slide 40 text
Range 1..5 (1..5).to_a # [1,2,3,4,5]
Slide 41
Slide 41 text
Range 1..5 (1..5).to_a # [1,2,3,4,5] Not available
Slide 42
Slide 42 text
Range 1..5 (1..5).to_a # [1,2,3,4,5] 1..5 1..5 |> Enum.to_list # [1,2,3,4,5] Not available
Slide 43
Slide 43 text
If statement if true # unless puts "It's true" else puts "It's false" end true ? "it's true" : "it's false"
Slide 44
Slide 44 text
If statement if (true) { console.log("It's true") } else { console.log("It's false") } true ? "it's true" : "it's false"
Slide 45
Slide 45 text
If statement if true do # unless IO.puts "It's true" else IO.puts "It's false" end if true, do: "It's true", else: "it's false"
Slide 46
Slide 46 text
Case case true when true "It's true" when false "It’s false" else "Something else" end
Slide 47
Slide 47 text
Case switch(true) { case true: "It's true" break; case false: "It's false" break; default: "Something else" }
Slide 48
Slide 48 text
Case case true do true -> "It’s true" false -> "It’s false" _ -> "Something else" end
Slide 49
Slide 49 text
Pipe operator [1, 2, 3, 4, 6]. map{ |x| x*x }. reduce{ |sum, x| sum + x }
Slide 50
Slide 50 text
Pipe operator [1, 2, 3, 4, 6] .map(x => x * x) .reduce((x, sum) => sum + x) [1, 2, 3, 4, 6]. map{ |x| x*x }. reduce{ |sum, x| sum + x }
Slide 51
Slide 51 text
Pipe operator [1, 2, 3, 4, 6] .map(x => x * x) .reduce((x, sum) => sum + x) [1, 2, 3, 4, 6] |> Enum.map(fn x -> x*x end) |> Enum.reduce(fn x, sum -> sum + x end) [1, 2, 3, 4, 6]. map{ |x| x*x }. reduce{ |sum, x| sum + x }
Slide 52
Slide 52 text
Comprehensions for x in [1,2,3] do puts x end
Slide 53
Slide 53 text
Comprehensions for x in [1,2,3] do puts x end for (x in [1,2,3]) { console.log(x) }
Slide 54
Slide 54 text
Comprehensions for x <- [1,2,3] do IO.puts x end for x in [1,2,3] do puts x end for (x in [1,2,3]) { console.log(x) }
Slide 55
Slide 55 text
Anonymous function irb(main):010:0> hello = -> what { puts "Hello #{what}" } => # irb(main):011:0> hello.("what") # hello.call("what") "Hello what" => nil
Slide 56
Slide 56 text
Anonymous function irb(main):010:0> hello = -> what { puts "Hello #{what}" } => # irb(main):011:0> hello.("what") # hello.call("what") "Hello what" => nil > const hello = (what) => { return `Hello ${what}`; } undefined > hello("world") 'Hello world'
Slide 57
Slide 57 text
Anonymous function iex(10)> hello = fn what -> IO.puts "Hello #{what}" end #Function<7.126501267/1 in :erl_eval.expr/5> iex(11)> hello.("world") Hello world :ok irb(main):010:0> hello = -> what { puts "Hello #{what}" } => # irb(main):011:0> hello.("what") # hello.call("what") "Hello what" => nil > const hello = (what) => { return `Hello ${what}`; } undefined > hello("world") 'Hello world'
Slide 58
Slide 58 text
Code A bit of code
Slide 59
Slide 59 text
Define module and function module ModuleName def hello puts "Hello Ruby!" end end
Slide 60
Slide 60 text
Define module and function* class ClassName { hello() { return `Hello from JS`; } }
Slide 61
Slide 61 text
Define module and function defmodule ModuleName do def hello do puts "Hello from Elixir" end end
Slide 62
Slide 62 text
Syntax Sugar Sweet ● Brackets ● Keyword list
Slide 63
Slide 63 text
Companies Use the Elixir ● Discord ● Sketch ● Pinterest ● Bleacher Report ● PepsiCo ● Whatsapp ● Financial Times
Slide 64
Slide 64 text
Questions? Thank you!