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
360
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
41
How I have built Telegram bot for study German
vermaxik
0
370
Other Decks in Programming
See All in Programming
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
590
XP, Testing and ninja testing
m_seki
3
250
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
19k
技術同人誌をMCP Serverにしてみた
74th
1
660
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
190
AIプログラマーDevinは PHPerの夢を見るか?
shinyasaita
1
230
生成AI時代のコンポーネントライブラリの作り方
touyou
1
250
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
500
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
2.2k
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
700
ご注文の差分はこちらですか? 〜 AWS CDK のいろいろな差分検出と安全なデプロイ
konokenj
2
110
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
130
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Raft: Consensus for Rubyists
vanstee
140
7k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
980
Six Lessons from altMBA
skipperchong
28
3.9k
4 Signs Your Business is Dying
shpigford
184
22k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Rails Girls Zürich Keynote
gr2m
95
14k
How to Ace a Technical Interview
jacobian
278
23k
A Modern Web Designer's Workflow
chriscoyier
695
190k
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!