Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
OOP in Elixir
Search
Wojtek Mach
February 17, 2016
330
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
OOP in Elixir
Wojtek Mach
February 17, 2016
Transcript
38 slides
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
More Decks by Wojtek Mach
See All by Wojtek Mach
Writing an Ecto Adapter: Introducing MyXQL
wojtekmach
1
190
Hex Core
wojtekmach
0
180
Recurrences & Intervals
wojtekmach
2
540
Building an Umbrella Project
wojtekmach
21
6.2k
Advanced OOP in Elixir
wojtekmach
6
690
Pattern Matching
wojtekmach
1
350
Formatting ruby code
wojtekmach
0
160
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.7k
Skip the Path - Find Your Career Trail
mkilby
1
290
Building Applications with DynamoDB
mza
96
7.3k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
810
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
330
Unsuck your backbone
ammeep
672
58k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3.1k
Google's AI Overviews - The New Search
badams
0
1.7k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
240
How GitHub (no longer) Works
holman
316
150k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
830
Design in an AI World
tapps
1
390