Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Elixir vs Ruby vs JavaScript Syntax
Search
Maksym Verbovyi
August 23, 2020
Programming
0
350
Elixir vs Ruby vs JavaScript Syntax
Compare Elixir syntax with Ruby and JavaScript #elixirschool
Maksym Verbovyi
August 23, 2020
Tweet
Share
More Decks by Maksym Verbovyi
See All by Maksym Verbovyi
Phoenix LiveView - interactive real-time apps without writing JS
vermaxik
0
40
How I have built Telegram bot for study German
vermaxik
0
370
Other Decks in Programming
See All in Programming
Enterprise Web App. Development (2): Version Control Tool Training Ver. 5.1
knakagawa
1
110
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
2k
KotlinConf 2025 現地で感じたServer-Side Kotlin
n_takehata
1
220
Rails産でないDBを Railsに引っ越すHACK - Omotesando.rb #110
lnit
1
160
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
120
ktr0731/go-mcpでMCPサーバー作ってみた
takak2166
0
170
Practical Tips and Tricks for Working with Compose Multiplatform Previews (mDevCamp 2025)
stewemetal
0
120
try-catchを使わないエラーハンドリング!? PHPでResult型の考え方を取り入れてみよう
kajitack
3
510
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
740
Datadog RUM 本番導入までの道
shinter61
1
290
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
500
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
210
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
39
1.8k
Making Projects Easy
brettharned
116
6.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.9k
Building an army of robots
kneath
306
45k
Fireside Chat
paigeccino
37
3.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Code Reviewing Like a Champion
maltzj
524
40k
Transcript
Elixir vs Ruby vs JavaScript Syntax Elixir School Maksym Verbovyi
August 2020, Hamburg
Disclaimer
Basics Tools and common usage
Interactive Shell iex irb jsc
Run task mix rake npm
Dependencies mix bundler npm
Debug IEX.pry binding.pry debugger
Polymorphism Protocols Polymorphism Extends
Metaprogramming Macros Metaprogramming Proxy Reflect
Popular framework Phoenix Rails React Vue.js
Syntax Be awesome
String "String" 'string'
String "String" 'string' "String" 'string'
String "String" 'Not string' # [110, 111, 116, 32, 115,
116, 114, 105, 110, 103] "String" 'string' "String" 'string'
Atom :symbol
Atom Symbol('string') :symbol
Atom Symbol('string') :symbol :atom
Boolean true || false
Boolean true || false true || false
Boolean true || false true || false true || false
List [1, :a, "b", true] *
List [1, Symbol('a'), "b", true] * [1, :a, "b", true]
*
List [1, :a, "b", true] [1, Symbol('a'), "b", true] *
[1, :a, "b", true] *
Tuple {1, :a, "b", true} [1, Symbol('a'), "b", true] *
[1, :a, "b", true] *
Map { name: "Maks", age: 32, height: 178 }
Map { name: "Maks", age: 32, height: 178 } {
name: "Maks", age: 32, height: 178 }
Map %{ name: "Maks", age: 32, height: 178 } {
name: "Maks", age: 32, height: 178 } { name: "Maks", age: 32, height: 178 }
Nil nil
Nil nil null
Nil nil nil null
Interpolation "Hello #{ruby}"
Interpolation "Hello #{ruby}" `Hello ${javascript}`
Interpolation "Hello #{ruby}" "Hello #{elixir}" `Hello ${javascript}`
Concatenation String "Elixir" + "School" "Elixir" << "School" "Elixir".concat("School")
Concatenation String "Elixir" + "School" "Elixir" << "School" "Elixir".concat("School") "Elixir"
+ "School" "Elixir".concat("School")
Concatenation String "Elixir" + "School" "Elixir" << "School" "Elixir".concat("School") "Elixir"
+ "School" "Elixir".concat("School") "Hello" <> "Elixir"
Concatenation List [1,2,3] + [4,5] # [1,2,3,4,5] [1,2] << 3
# [1,2,3]
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]
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]
Range 1..5 (1..5).to_a # [1,2,3,4,5]
Range 1..5 (1..5).to_a # [1,2,3,4,5] Not available
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
If statement if true # unless puts "It's true" else
puts "It's false" end true ? "it's true" : "it's false"
If statement if (true) { console.log("It's true") } else {
console.log("It's false") } true ? "it's true" : "it's false"
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"
Case case true when true "It's true" when false "It’s
false" else "Something else" end
Case switch(true) { case true: "It's true" break; case false:
"It's false" break; default: "Something else" }
Case case true do true -> "It’s true" false ->
"It’s false" _ -> "Something else" end
Pipe operator [1, 2, 3, 4, 6]. map{ |x| x*x
}. reduce{ |sum, x| sum + x }
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 }
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 }
Comprehensions for x in [1,2,3] do puts x end
Comprehensions for x in [1,2,3] do puts x end for
(x in [1,2,3]) { console.log(x) }
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) }
Anonymous function irb(main):010:0> hello = -> what { puts "Hello
#{what}" } => #<Proc:0x00007fb13f0e8da8@(irb):10 (lambda)> irb(main):011:0> hello.("what") # hello.call("what") "Hello what" => nil
Anonymous function irb(main):010:0> hello = -> what { puts "Hello
#{what}" } => #<Proc:0x00007fb13f0e8da8@(irb):10 (lambda)> irb(main):011:0> hello.("what") # hello.call("what") "Hello what" => nil > const hello = (what) => { return `Hello ${what}`; } undefined > hello("world") 'Hello world'
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}" } => #<Proc:0x00007fb13f0e8da8@(irb):10 (lambda)> irb(main):011:0> hello.("what") # hello.call("what") "Hello what" => nil > const hello = (what) => { return `Hello ${what}`; } undefined > hello("world") 'Hello world'
Code A bit of code
Define module and function module ModuleName def hello puts "Hello
Ruby!" end end
Define module and function* class ClassName { hello() { return
`Hello from JS`; } }
Define module and function defmodule ModuleName do def hello do
puts "Hello from Elixir" end end
Syntax Sugar Sweet • Brackets • Keyword list
Companies Use the Elixir • Discord • Sketch • Pinterest
• Bleacher Report • PepsiCo • Whatsapp • Financial Times
Questions? Thank you!