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
210
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
32
How I have built Telegram bot for study German
vermaxik
0
150
Other Decks in Programming
See All in Programming
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
930
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
170
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
190
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
940
Rethinking UI building strategies @ SFI 2024
letelete
0
270
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
ゆるい個人開発のススメ
kuroppe1819
10
990
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
360
VS Code をプロダクトにどう取り込むか
onomax
1
360
Let's learn code review
riofujimon
2
340
雑に思考を整理する技術と効能
konifar
60
29k
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
Clear Off the Table
cherdarchuk
84
310k
Designing for humans not robots
tammielis
248
25k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
Creatively Recalculating Your Daily Design Routine
revolveconf
210
11k
What the flash - Photography Introduction
edds
64
11k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
357
22k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
Optimizing for Happiness
mojombo
370
69k
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!