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
330
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
37
How I have built Telegram bot for study German
vermaxik
0
330
Other Decks in Programming
See All in Programming
PHPで書いたAPIをGoに書き換えてみた 〜パフォーマンス改善の可能性を探る実験レポート〜
koguuum
0
150
生成AIを使ったQAアプリケーションの作成 - ハンズオン補足資料
oracle4engineer
PRO
3
210
Coding Experience Cpp vs Csharp - meetup app osaka@9
harukasao
0
740
サービスレベルを管理してアジャイルを加速しよう!! / slm-accelerate-agility
tomoyakitaura
1
170
The Implementations of Advanced LR Parser Algorithm
junk0612
0
240
Vibe Codingをせずに Clineを使っている
watany
17
6.2k
Unlock the Potential of Swift Code Generation
rockname
0
250
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.4k
AWS で実現する安全な AI エージェントの作り方 〜 Bedrock Engineer の実装例を添えて 〜 / how-to-build-secure-ai-agents
gawa
8
780
Code smarter, not harder - How AI Coding Tools Boost Your Productivity | Webinar 2025
danielsogl
0
120
リアクティブシステムの変遷から理解するalien-signals / Learning alien-signals from the evolution of reactive systems
yamanoku
3
1.2k
リストビュー画面UX改善の振り返り
splcywolf
0
130
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
135
33k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.2k
How to Ace a Technical Interview
jacobian
276
23k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.3k
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!