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
320
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
OOP in Elixir
Wojtek Mach
February 17, 2016
More Decks by Wojtek Mach
See All by Wojtek Mach
Writing an Ecto Adapter: Introducing MyXQL
wojtekmach
1
170
Hex Core
wojtekmach
0
160
Recurrences & Intervals
wojtekmach
2
510
Building an Umbrella Project
wojtekmach
21
6.1k
Advanced OOP in Elixir
wojtekmach
6
680
Pattern Matching
wojtekmach
1
330
Formatting ruby code
wojtekmach
0
140
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
We Have a Design System, Now What?
morganepeng
55
8.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Exploring anti-patterns in Rails
aemeredith
3
400
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
A Soul's Torment
seathinner
6
2.9k
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