SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
Tell a good story with Ruby
{slide: 'http://goo.gl/Sfl0RF'}
I.am ' '
@taiansu
co-organizer of RailsGirls
Taipei
work for OptimisDev
I.was "a computer magazine editor", 8.years.ago
I.write_code? #=> false
So why I'm here?
I.start_coding from: "Two books"
Special Thanks
Learn to Program
by Chis Pine
Ruby
by
Ruby Programming - Ruby
Native Language alike
to configureTheDisplay(theProfilesName, brightnessValue)
tell application "System Events"
*if not* UI elements enabled then
DisplayAssistanceInstructions() *of me*
return
*end if*
openDisplaysPrefPane() *of me*
tell process "System Preferences"
click radio button "Display" of tab group 1 of window 1
*end tell*
quitPrefs() *of me*
*end tell*
return
end configureTheDisplay
But even in projects using Ruby...
def page201(from_page, visited_queen = false, threw_button = false)
if from_page == 59
fall_down_to_sinkhole
else
exit_the_passageway
end
enemy = if visit_queen
Badger.new
elsif threw_button
nil
else
Trollnew
end
enemy.angry if enemy
# ... 30 lines of code
end
Good story, poorly told.
Books of "Choose your own adventure"
• If you fight the troll with bare hands, turn to page 137.
• If you try to reason with the troll, turn to page 29.
• If you don your invisibility clock, turn to page 6.
What if you read this kind of book from the first
page to the end?
You exit the passageway into a large cavern. Unless you came from
page 59, in which case you fall down the sinkhole into a large cavern.
A huge troll, or possibly a badger ( if you already visited Queen
Pelican), blocks your path. Unless your threw a button down the
wishing well on page 8, in which case there nothing blocking your
way. The [troll or badger or nothing at all] does not look happy to see
you.
Chinese Version
59
(
)
def page201(from_page, visit_queen = false, threw_button = false)
if from_page == 59
fall_down_to_sinkhole
else
exit_the_passageway
end
enemy = if visit_queen
Badger.new
elsif threw_button
nil
else
Trollnew
end
enemy.angry if enemy
# ...
end
Two TV Serises
MacGyver
vs.
Mission Impossible
Sending strong message
The foundation of an object oriented system is the message.
— Sandi Metz, Practical Object-Oriented Design in Ruby
Tell a better story
1. Identify the message to be send
2. Find the roles which correspond to those messages
3. Ensure the methods's logic receives objects which can play those
roles.
Identify the message to be send
*Tell, don't ask
A story of parse many legacy CSV files of purchase
records
1. Parse the purchase records from the CSV contained in a provided
IO object.
2. For each purchase record, use the record's email address to get
the associated customer record, or, if the email hasn't been seen
before, create a new customer record in our system.
3. Use the legacy record's product ID to find or create a product
record in our system.
4. Add the product to the customer record's list of purchases.
1. #parse_legacypurchase_records.
2. For #each purchase record, use the record's #email_address to
#get_customer.
3. Use the record's #product_id to #get_product.
4. #add_purchasedproduct to the customer record.
5. #notify_offiles_available for the purchased product.
6. #log_successfulimport of the product record.
Find the roles which correspond to
those messages
*Single responsibility principle
Message => Receiver Role
• #parselegacypurchaserecords
=> *legacydata_parser*
• #each
=> purchase_list
• #emailaddress, #productid
=> purchase_record
• #getcustomer
=> customerlist
etc...
Ensure the methods's logic receives
objects which can play those roles.
*Law of Demeter
1. legacydataparser.parsepurchaserecords.
2. For purchase_list.each as purchase_record, use
purchaserecord.emailaddress to customerlist.getcustomer.
3. Use the purchaserecord.productid to productinventory.getproduct.
4. customer.addpurchasedproduct.
5. customer.notifyoffiles_available for the product.
6. self.logsuccessfulimport of the purchase_record.
def import_legacy_purchase_data(data)
purchase_list = legacy_data_parser.parse_purchase_records(data)
purchase_list.each do |purchase_record|
customer = customer_list.get_customer(purchase_record.email_address)
product = product_inventory.get_product(purchase_record.product_id)
customer.add_purchased_product(product)
customer.notify_of_files_available(product)
log_successful_import(purchase_record)
end
end
Now it starting to look a lot like code.
Don't Know Where to Start?
Let's talk about method
Four parts of every method
1. collecting inputs
2. performing works
3. delivering output
4. handling failures
• diagnostics and cleanup
Some More Tips
1. Workround: Glue of the existing tools to perform works.
2. Refactor: Focus on Inrtent of a method rather than method's
environment
3. One level of abstraction each layer.
4. Pair Programming helps.
5. Some times TDD is a good indicator.
Books Recommendation
Practical object-
oriented design in
Ruby
by Sandi Metz
Confident Ruby
by Avdi Grimm
Questions?

Más contenido relacionado

Similar a Tell a good story with

Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
PatchSpace Ltd
 

Similar a Tell a good story with (20)

Planning JavaScript for Larger Teams - Draft & Handout version
Planning JavaScript for Larger Teams - Draft & Handout versionPlanning JavaScript for Larger Teams - Draft & Handout version
Planning JavaScript for Larger Teams - Draft & Handout version
 
The Sieve of Eratosthenes - Part 1 - with minor corrections
The Sieve of Eratosthenes - Part 1 - with minor correctionsThe Sieve of Eratosthenes - Part 1 - with minor corrections
The Sieve of Eratosthenes - Part 1 - with minor corrections
 
The Sieve of Eratosthenes - Part 1
The Sieve of Eratosthenes - Part 1The Sieve of Eratosthenes - Part 1
The Sieve of Eratosthenes - Part 1
 
The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
All of javascript
All of javascriptAll of javascript
All of javascript
 
What NOT to test in your project
What NOT to test in your projectWhat NOT to test in your project
What NOT to test in your project
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Mobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B ExperimentsMobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B Experiments
 
The Black Magic of Ruby Metaprogramming
The Black Magic of Ruby MetaprogrammingThe Black Magic of Ruby Metaprogramming
The Black Magic of Ruby Metaprogramming
 
Boxen: How to Manage an Army of Laptops and Live to Talk About It
Boxen: How to Manage an Army of Laptops and Live to Talk About ItBoxen: How to Manage an Army of Laptops and Live to Talk About It
Boxen: How to Manage an Army of Laptops and Live to Talk About It
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
 
Good Coding Practices with JavaScript
Good Coding Practices with JavaScriptGood Coding Practices with JavaScript
Good Coding Practices with JavaScript
 
Ruby For Startups
Ruby For StartupsRuby For Startups
Ruby For Startups
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

Tell a good story with

  • 1. Tell a good story with Ruby {slide: 'http://goo.gl/Sfl0RF'}
  • 2. I.am ' ' @taiansu co-organizer of RailsGirls Taipei work for OptimisDev
  • 3. I.was "a computer magazine editor", 8.years.ago I.write_code? #=> false
  • 4. So why I'm here?
  • 5. I.start_coding from: "Two books" Special Thanks
  • 8. Native Language alike to configureTheDisplay(theProfilesName, brightnessValue) tell application "System Events" *if not* UI elements enabled then DisplayAssistanceInstructions() *of me* return *end if* openDisplaysPrefPane() *of me* tell process "System Preferences" click radio button "Display" of tab group 1 of window 1 *end tell* quitPrefs() *of me* *end tell* return end configureTheDisplay
  • 9. But even in projects using Ruby... def page201(from_page, visited_queen = false, threw_button = false) if from_page == 59 fall_down_to_sinkhole else exit_the_passageway end enemy = if visit_queen Badger.new elsif threw_button nil else Trollnew end enemy.angry if enemy # ... 30 lines of code end
  • 11. Books of "Choose your own adventure" • If you fight the troll with bare hands, turn to page 137. • If you try to reason with the troll, turn to page 29. • If you don your invisibility clock, turn to page 6.
  • 12. What if you read this kind of book from the first page to the end? You exit the passageway into a large cavern. Unless you came from page 59, in which case you fall down the sinkhole into a large cavern. A huge troll, or possibly a badger ( if you already visited Queen Pelican), blocks your path. Unless your threw a button down the wishing well on page 8, in which case there nothing blocking your way. The [troll or badger or nothing at all] does not look happy to see you.
  • 14. def page201(from_page, visit_queen = false, threw_button = false) if from_page == 59 fall_down_to_sinkhole else exit_the_passageway end enemy = if visit_queen Badger.new elsif threw_button nil else Trollnew end enemy.angry if enemy # ... end
  • 16.
  • 17.
  • 19. Sending strong message The foundation of an object oriented system is the message. — Sandi Metz, Practical Object-Oriented Design in Ruby
  • 20. Tell a better story 1. Identify the message to be send 2. Find the roles which correspond to those messages 3. Ensure the methods's logic receives objects which can play those roles.
  • 21. Identify the message to be send *Tell, don't ask
  • 22. A story of parse many legacy CSV files of purchase records 1. Parse the purchase records from the CSV contained in a provided IO object. 2. For each purchase record, use the record's email address to get the associated customer record, or, if the email hasn't been seen before, create a new customer record in our system. 3. Use the legacy record's product ID to find or create a product record in our system. 4. Add the product to the customer record's list of purchases.
  • 23. 1. #parse_legacypurchase_records. 2. For #each purchase record, use the record's #email_address to #get_customer. 3. Use the record's #product_id to #get_product. 4. #add_purchasedproduct to the customer record. 5. #notify_offiles_available for the purchased product. 6. #log_successfulimport of the product record.
  • 24. Find the roles which correspond to those messages *Single responsibility principle
  • 25. Message => Receiver Role • #parselegacypurchaserecords => *legacydata_parser* • #each => purchase_list • #emailaddress, #productid => purchase_record • #getcustomer => customerlist etc...
  • 26. Ensure the methods's logic receives objects which can play those roles. *Law of Demeter
  • 27. 1. legacydataparser.parsepurchaserecords. 2. For purchase_list.each as purchase_record, use purchaserecord.emailaddress to customerlist.getcustomer. 3. Use the purchaserecord.productid to productinventory.getproduct. 4. customer.addpurchasedproduct. 5. customer.notifyoffiles_available for the product. 6. self.logsuccessfulimport of the purchase_record.
  • 28. def import_legacy_purchase_data(data) purchase_list = legacy_data_parser.parse_purchase_records(data) purchase_list.each do |purchase_record| customer = customer_list.get_customer(purchase_record.email_address) product = product_inventory.get_product(purchase_record.product_id) customer.add_purchased_product(product) customer.notify_of_files_available(product) log_successful_import(purchase_record) end end Now it starting to look a lot like code.
  • 29. Don't Know Where to Start? Let's talk about method
  • 30. Four parts of every method 1. collecting inputs 2. performing works 3. delivering output 4. handling failures • diagnostics and cleanup
  • 31.
  • 32. Some More Tips 1. Workround: Glue of the existing tools to perform works. 2. Refactor: Focus on Inrtent of a method rather than method's environment 3. One level of abstraction each layer. 4. Pair Programming helps. 5. Some times TDD is a good indicator.
  • 34. Practical object- oriented design in Ruby by Sandi Metz