SlideShare a Scribd company logo
1 of 39
Download to read offline
Font Test: Liberation Sans
I am monospace font
and kinda important, 32pt,
Ok?
LibreOffice
ife!!!
“orange”?
J
July 2017
September 2019
TRB in 90 sec.TRB in 90 sec.TRB in 90 sec.
1.0
class CommentsController
def update
run Comment::Update
end
2.0
class Comment::Update < …::Operation
step :find_model
step :validate
step :save
fail :alert_admin
step :notify_admin
nd
2.1
Nightmare on
else Street
def run_circuit(options)
steps.each do |step|
trace(options, step) if TRACING == true
step.call(options)
end
end
The Story of Trailblazer 3.0
is The Story of ifs.
2.1
if
Nick Sutterer
If is like vodka.
If you over-use it,
you get a headache.
Operative ifs vs. structural ifs
if email =~ /@/
else
end
if user.status == :suspended
&& action == :vote
raise “not allowed”
else
end
Business processes will always be
complex, son. There ain’t no way
to, like, simplify those.
But there are good and, eh, bad
tools to deal with… yeah, right,
complexity!
– Donald Trump, 1644
“
Pull
Requests,
yay!
+ if MYCOMPANY == true
+ img_path = “mycomp/imgs” + “hi.jpg”
+ img = image_tag(path)
+ section = content_for(:blog, img)
+ else
img_path = “/imgs” + “hi.jpg”
img = image_tag(path)
section = content_for(blog_name, img)
Milestone Codename
1.2.3 “Hello world”
2.0.0 “Hello world” 2.0.0
3.0.0 The Merb merge™
3.1.0 @wycats’s Revenge
4.0
5.0 Chatbot
6.0 Typo3 Drupal
X
rails$ wc -l respond_to?
129
if association.respond_to?(:to_ary)
Duck typing?
An object's suitability is determined by
the presence of certain methods [..],
rather than the type of the object itself.
– Wikipedia
LBYL
Look before you leap.
if
EAFP
Easier to ask for forgiveness than permission.
try/rescue
Compressive behavior of CNT in
polymer matrix with strong interfaces
obj.method_i_know #=> yay, works
obj.unknown_method #=> throw a
fucking
exception
class Developer
implements Attendee
def drink_shot()
end
end
class HRManager
implements Attendee
def drink_shot()
end
end
def celebrate(attendee)
attendee.drink_shot()
end
def celebrate(Attendee attendee)
attendee.drink_shot()
end
STATIC
TYPING def celebrate(Attendee attendee)
celebrate(conference)
#=> compile-time error <3
if obj.is_a?(Conference)
raise “wrong argument!”
elsif obj.is_a?(Attendee)
# do it!
Method
Overloading
def celebrate(Attendee user)
user.drink_shot()
endattendee)
def celebrate(Conference conf)
conf.provide_free_beers_tonight()
endattendee)
# *cough*
if obj.is_a?(Conference)
handle_conf(obj)
elsif obj.is_a?(Attendee)
handle_attendee(obj)
Functional API
class Attendee
def attend(conference)
def celebrate
raise if @is_attending.nil?
class Attendee
public def live(conference)
attend(conference)
celebrate
end
OOP
Parametrization,
cause we can!
if MYCOMPANY == true
img_path = “mycomp/imgs” + “hi.jpg”
img = image_tag(path)
section = content_for(:blog, img)
else
img_path = “/imgs” + “hi.jpg”
img = image_tag(path)
section = content_for(blog_name, img)
def render_section(path, content_name)
img_path = path + “hi.jpg”
img = image_tag(path)
section = content_for(content_name, img)
if MYCOMPANY == true
render_section(“mycomp/imgs”, :blog)
else
render_section(“img”, blog_name)
Dispatching hashaction =
if type == :attendee
:register
elsif type == :speaker
:wake_up
elsif type == :matz
:make_tea
# ...
actions = {
attendee: :register,
speaker: :wake_up,
matz: :make_tea,
} # Extendable!
action = actions[type] # no if!
MyActions.send(action) # no if!
“Dispatching Hash”
Glass on white background | Artist: N. Sutterer | 2019 | Abstract painting on vinyl | € 3299,-
def order_beer_for(person) when person in [:ivan, :nick] do
# do something
end
class Attendee::Update < Trailblazer::Operation
step :find_attendee
step :validate
step :save
fail :alert_admin
step :notify_admin
end
class Attendee::Update < Trailblazer::Operation
step :find_attendee
step :validate
step :save
fail :alert_admin
step :notify_admin
end
def process(…)
if find_attendee(…)
if validate(…)
if save(…)
if notify_admin(…)
else
alert_admin(…)
end
else
alert_admin(…)
end
else
alert_admin(…)
end
end
class Attendee::Update < Trailblazer::Operation
step :find_attendee
step :validate
step :save
fail :alert_admin
step :notify_admin
end
activity Attendee::Update
step :find_attendee
step :validate
step :save
fail :alert_admin
step :notify_admin
end
trace(options) if TRACING == true
“Trust us”
...and now,
my dear friends,
let’s if together!
@apotonick
If - The Vodka of Ruby

More Related Content

Similar to If - The Vodka of Ruby

Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3aRuth Marvin
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Blocks by Lachs Cox
Blocks by Lachs CoxBlocks by Lachs Cox
Blocks by Lachs Coxlachie
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test communityKerry Buckley
 
Forumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate AffairForumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate Affairguest06ed72
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Plataformatec
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming ProjectSage Jacobs
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsLeonardo Borges
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 

Similar to If - The Vodka of Ruby (20)

Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
Ruby Intro {spection}
Ruby Intro {spection}Ruby Intro {spection}
Ruby Intro {spection}
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Beware sharp tools
Beware sharp toolsBeware sharp tools
Beware sharp tools
 
R Debugging
R DebuggingR Debugging
R Debugging
 
Blocks by Lachs Cox
Blocks by Lachs CoxBlocks by Lachs Cox
Blocks by Lachs Cox
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
Forumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate AffairForumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate Affair
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming Project
 
The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

If - The Vodka of Ruby

  • 1. Font Test: Liberation Sans I am monospace font and kinda important, 32pt, Ok? LibreOffice ife!!! “orange”?
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. TRB in 90 sec.TRB in 90 sec.TRB in 90 sec. 1.0 class CommentsController def update run Comment::Update end 2.0 class Comment::Update < …::Operation step :find_model step :validate step :save fail :alert_admin step :notify_admin nd 2.1
  • 9. Nightmare on else Street def run_circuit(options) steps.each do |step| trace(options, step) if TRACING == true step.call(options) end end
  • 10. The Story of Trailblazer 3.0 is The Story of ifs. 2.1
  • 12. If is like vodka. If you over-use it, you get a headache.
  • 13. Operative ifs vs. structural ifs if email =~ /@/ else end if user.status == :suspended && action == :vote raise “not allowed” else end
  • 14. Business processes will always be complex, son. There ain’t no way to, like, simplify those. But there are good and, eh, bad tools to deal with… yeah, right, complexity! – Donald Trump, 1644 “
  • 16. + if MYCOMPANY == true + img_path = “mycomp/imgs” + “hi.jpg” + img = image_tag(path) + section = content_for(:blog, img) + else img_path = “/imgs” + “hi.jpg” img = image_tag(path) section = content_for(blog_name, img)
  • 17. Milestone Codename 1.2.3 “Hello world” 2.0.0 “Hello world” 2.0.0 3.0.0 The Merb merge™ 3.1.0 @wycats’s Revenge 4.0 5.0 Chatbot 6.0 Typo3 Drupal X rails$ wc -l respond_to? 129 if association.respond_to?(:to_ary)
  • 18. Duck typing? An object's suitability is determined by the presence of certain methods [..], rather than the type of the object itself. – Wikipedia
  • 19. LBYL Look before you leap. if EAFP Easier to ask for forgiveness than permission. try/rescue
  • 20. Compressive behavior of CNT in polymer matrix with strong interfaces
  • 21. obj.method_i_know #=> yay, works obj.unknown_method #=> throw a fucking exception
  • 22. class Developer implements Attendee def drink_shot() end end class HRManager implements Attendee def drink_shot() end end def celebrate(attendee) attendee.drink_shot() end def celebrate(Attendee attendee) attendee.drink_shot() end
  • 23. STATIC TYPING def celebrate(Attendee attendee) celebrate(conference) #=> compile-time error <3 if obj.is_a?(Conference) raise “wrong argument!” elsif obj.is_a?(Attendee) # do it!
  • 24. Method Overloading def celebrate(Attendee user) user.drink_shot() endattendee) def celebrate(Conference conf) conf.provide_free_beers_tonight() endattendee) # *cough* if obj.is_a?(Conference) handle_conf(obj) elsif obj.is_a?(Attendee) handle_attendee(obj)
  • 25. Functional API class Attendee def attend(conference) def celebrate raise if @is_attending.nil? class Attendee public def live(conference) attend(conference) celebrate end OOP
  • 26. Parametrization, cause we can! if MYCOMPANY == true img_path = “mycomp/imgs” + “hi.jpg” img = image_tag(path) section = content_for(:blog, img) else img_path = “/imgs” + “hi.jpg” img = image_tag(path) section = content_for(blog_name, img) def render_section(path, content_name) img_path = path + “hi.jpg” img = image_tag(path) section = content_for(content_name, img) if MYCOMPANY == true render_section(“mycomp/imgs”, :blog) else render_section(“img”, blog_name)
  • 27. Dispatching hashaction = if type == :attendee :register elsif type == :speaker :wake_up elsif type == :matz :make_tea # ... actions = { attendee: :register, speaker: :wake_up, matz: :make_tea, } # Extendable! action = actions[type] # no if! MyActions.send(action) # no if! “Dispatching Hash”
  • 28. Glass on white background | Artist: N. Sutterer | 2019 | Abstract painting on vinyl | € 3299,-
  • 29. def order_beer_for(person) when person in [:ivan, :nick] do # do something end
  • 30. class Attendee::Update < Trailblazer::Operation step :find_attendee step :validate step :save fail :alert_admin step :notify_admin end
  • 31. class Attendee::Update < Trailblazer::Operation step :find_attendee step :validate step :save fail :alert_admin step :notify_admin end def process(…) if find_attendee(…) if validate(…) if save(…) if notify_admin(…) else alert_admin(…) end else alert_admin(…) end else alert_admin(…) end end
  • 32. class Attendee::Update < Trailblazer::Operation step :find_attendee step :validate step :save fail :alert_admin step :notify_admin end activity Attendee::Update step :find_attendee step :validate step :save fail :alert_admin step :notify_admin end
  • 33.
  • 35.
  • 36.
  • 38. ...and now, my dear friends, let’s if together! @apotonick