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
OOP in Elixir
Search
Wojtek Mach
February 17, 2016
4
290
OOP in Elixir
Wojtek Mach
February 17, 2016
Tweet
Share
More Decks by Wojtek Mach
See All by Wojtek Mach
Writing an Ecto Adapter: Introducing MyXQL
wojtekmach
1
130
Hex Core
wojtekmach
0
130
Recurrences & Intervals
wojtekmach
2
420
Building an Umbrella Project
wojtekmach
21
5.7k
Advanced OOP in Elixir
wojtekmach
6
640
Pattern Matching
wojtekmach
1
290
Formatting ruby code
wojtekmach
0
110
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Building Adaptive Systems
keathley
38
2.4k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Optimising Largest Contentful Paint
csswizardry
33
3k
BBQ
matthewcrist
85
9.4k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
Visualization
eitanlees
146
15k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Transcript
OOP in Elixir Wojtek Mach
defmodule Person do defstruct [:name] end joe = %Person{name: "Joe"}
robert = %Person{name: "Robert"} joe.name # => "Joe" robert.name # => "Robert"
defmodule Person do defstruct [:name] def say_hello_to(from, to) do IO.puts("#{from.name}:
Hello, #{to.name}") end end joe = %Person{name: "Joe"} robert = %Person{name: "Robert"} joe.name # => "Joe" robert.name # => "Robert" Person.say_hello_to(joe, robert) # => Joe: Hello, Robert
None
import OOP
import OOP class Person do var :name end
import OOP class Person do var :name end joe =
Person.new(name: "Joe") robert = Person.new(name: "Robert")
import OOP class Person do var :name end joe =
Person.new(name: "Joe") robert = Person.new(name: "Robert") joe.name() # => "Joe" robert.name # => "Robert"
import OOP class Person do var :name def say_hello_to(who) do
IO.puts("#{this.name}: #{who.name}") end end joe = Person.new(name: "Joe") robert = Person.new(name: "Robert") joe.name() # => "Joe" robert.name # => "Robert" joe.say_hello_to(robert) # => Joe: Hello, Robert
import class var def end end joe robert joe.name() #
=> "Joe" robert.name # => "Robert" joe.say_hello_to(robert) # => Joe: Hello, Robert this.name
joe = Person.new(name: "Joe") joe.set_name("Hipster Joe") # => :ok joe.name
# => "Hipster Joe"
Q: How does it work?
Q: How does it work? A: You don’t want to
know.
Q: How does it work? A: Macros.
Perhaps it’s not that bad…
Q: What’s worse than OOP?
Q: What’s worse than OOP? A: OOP with inheritance.
import OOP class Human do var :name end
import OOP class Human do var :name end class Doctor
< Human do end
import OOP class Human do var :name end class Doctor
< Human do def title do "Dr. #{name}" end end
import OOP class Human do var :name end class Doctor
< Human do def title do "Dr. #{name}" end end dr = Doctor.new(name: "Jekyll") dr.title # => "Dr. Jekyll"
Perhaps it’s not that bad…
Q: What’s worse than OOP with inheritance?
Q: What’s worse than OOP with inheritance? A: OOP with
multiple inheritance.
import OOP class Human do end
import OOP class Human do end class Spider do end
import OOP class Human do end class Spider do end
class Spiderman < [Human, Spider] do end
Elixir Guidelines
Q: What’s the 1st rule of writing macros? Elixir Guidelines
Q: What’s the 1st rule of writing macros? A: Don’t
write macros. Elixir Guidelines
Q: What’s the 1st rule of doing OOP in Elixir?
Elixir Guidelines
Q: What’s the 1st rule of doing OOP in Elixir?
A: Don’t do OOP in Elixir. Elixir Guidelines
None
• Elixir is powerful
• Elixir is powerful • DSLs, abstractions, semantics
• Elixir is powerful • DSLs, abstractions, semantics • Complexity
• Elixir is powerful • DSLs, abstractions, semantics • Complexity
• Simplicty
Thank you! @wojtekmach wojtekmach/oop