SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Confident Ruby
Be A Coding Hemingway
Confident Ruby
Avdi Grimm
http://www.rubytapas.com/
Doesn’t:

Does:

● Application Design

● Patterns for writing
confident Ruby
code at the method
level

● Object Modeling
“CODE
AS NARRATIVE”
Collecting Input
Performing Work
Delivering Output
Handling Errors
Responsibilities
Conversion Methods
Special Case Object
Receive Policies
Conversion Methods

Conversion Methods for Coercing Inputs
Type checking

Nested control structures
(‘if/else’ blocks)

Checking for ‘nil’ (type
checking)
Explicit Conversion
● #to_a, #to_i, #to_s
● objects don’t resemble the target type
● Implemented by Ruby types but not
called
Implicit Conversion
● #to_ary, #to_int, #to_str
● objects closely resemble the target type
● Called by Ruby but not implemented
Kernel Level Conversion Methods
● Array(), Integer(), String()
● Try implicit and explicit conversions
● Bag o’ tricks
Flexible
Coherent
Confident ; )
Conversion Methods

Special Case Object
Conversion Methods
=>
Special Case Object
● isolate the differences to a single object
● Leverage polymorphism by conforming to
a protocol
Confident
Expressive
Flexible

=>
“The foundation of an object
oriented system is the message”

-Sandi Metz, Practical Object-Oriented Design in Ruby
Conversion Methods

Receive Policies Instead of Data
Delegate Responsibility to Client Code
“Put the decision for how to handle
test cases in the hands of the code
best qualified to determine the
appropriate response.”
● Intent of the method
is obscured
● Calling code is not
self-documenting
● Little flexibility.
What if we want
more than 2 ways to
handle errors?

Passing data/flags
● Pass policies as
block/proc/lambda
objects
● Stop handling edge
cases from obfuscating
the method’s intent
● Flexibility - let’s the
client code handle
decision making

Passing Policies
Example: Ruby’s
Enumerable#detect
Write code that
tells a story
Confident Ruby - Avdi Grimm

Mais conteúdo relacionado

Mais procurados

IBus Chinese input methods for HongKongers - Problem, Solution, Future.
IBus Chinese input methods for HongKongers - Problem, Solution, Future.IBus Chinese input methods for HongKongers - Problem, Solution, Future.
IBus Chinese input methods for HongKongers - Problem, Solution, Future.
Sammy Fung
 

Mais procurados (8)

Enterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and servicesEnterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and services
 
Sharable of qualities of clean code
Sharable of qualities of clean codeSharable of qualities of clean code
Sharable of qualities of clean code
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
IBus Chinese input methods for HongKongers - Problem, Solution, Future.
IBus Chinese input methods for HongKongers - Problem, Solution, Future.IBus Chinese input methods for HongKongers - Problem, Solution, Future.
IBus Chinese input methods for HongKongers - Problem, Solution, Future.
 
Применение паттерна Page Object для автоматизации веб сервисов - новый взгляд
Применение паттерна Page Object для автоматизации веб сервисов - новый взглядПрименение паттерна Page Object для автоматизации веб сервисов - новый взгляд
Применение паттерна Page Object для автоматизации веб сервисов - новый взгляд
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 
Getting Started with the TypeScript Language
Getting Started with the TypeScript LanguageGetting Started with the TypeScript Language
Getting Started with the TypeScript Language
 
C# basics...
C# basics...C# basics...
C# basics...
 

Destaque

Diagnosing Infeasibilities in IMPL
Diagnosing Infeasibilities in IMPLDiagnosing Infeasibilities in IMPL
Diagnosing Infeasibilities in IMPL
Alkis Vazacopoulos
 
Skripsi Implementasi Hash Kriptografik
Skripsi Implementasi Hash KriptografikSkripsi Implementasi Hash Kriptografik
Skripsi Implementasi Hash Kriptografik
Arie Purwanto
 
Advanced Modeling of Industrial Optimization Problems
Advanced Modeling of Industrial Optimization ProblemsAdvanced Modeling of Industrial Optimization Problems
Advanced Modeling of Industrial Optimization Problems
Alkis Vazacopoulos
 
Digital lit daily hw and agenda
Digital lit daily hw and agendaDigital lit daily hw and agenda
Digital lit daily hw and agenda
janine420
 
social game의 전망
social game의 전망social game의 전망
social game의 전망
Jiye Park
 
Cloud computing
Cloud computingCloud computing
Cloud computing
Jiye Park
 
Animales
AnimalesAnimales
Animales
iippll
 
Social game
Social game Social game
Social game
Jiye Park
 

Destaque (20)

Gc in golang
Gc in golangGc in golang
Gc in golang
 
REST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesREST vs. Messaging For Microservices
REST vs. Messaging For Microservices
 
Diagnosing Infeasibilities in IMPL
Diagnosing Infeasibilities in IMPLDiagnosing Infeasibilities in IMPL
Diagnosing Infeasibilities in IMPL
 
Factors Affecting Balance in the Elderly Population
Factors Affecting Balance in the Elderly PopulationFactors Affecting Balance in the Elderly Population
Factors Affecting Balance in the Elderly Population
 
Skripsi Implementasi Hash Kriptografik
Skripsi Implementasi Hash KriptografikSkripsi Implementasi Hash Kriptografik
Skripsi Implementasi Hash Kriptografik
 
Goal setting - dr. s. swapna kumar
Goal  setting - dr. s. swapna kumarGoal  setting - dr. s. swapna kumar
Goal setting - dr. s. swapna kumar
 
Madapple slides
Madapple slidesMadapple slides
Madapple slides
 
Advanced Modeling of Industrial Optimization Problems
Advanced Modeling of Industrial Optimization ProblemsAdvanced Modeling of Industrial Optimization Problems
Advanced Modeling of Industrial Optimization Problems
 
Digital lit daily hw and agenda
Digital lit daily hw and agendaDigital lit daily hw and agenda
Digital lit daily hw and agenda
 
Partner
PartnerPartner
Partner
 
social game의 전망
social game의 전망social game의 전망
social game의 전망
 
Mulleres artistas
Mulleres artistasMulleres artistas
Mulleres artistas
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Pep.3
Pep.3Pep.3
Pep.3
 
Branding resources, Park Hill, North Little Rock, Arkansas
Branding resources, Park Hill, North Little Rock, ArkansasBranding resources, Park Hill, North Little Rock, Arkansas
Branding resources, Park Hill, North Little Rock, Arkansas
 
Impl reference manual_for_qualities
Impl reference manual_for_qualitiesImpl reference manual_for_qualities
Impl reference manual_for_qualities
 
Animales
AnimalesAnimales
Animales
 
Social game
Social game Social game
Social game
 
植物生理学第13回
植物生理学第13回植物生理学第13回
植物生理学第13回
 
Ph detailed dry district maps
Ph detailed dry district mapsPh detailed dry district maps
Ph detailed dry district maps
 

Último

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
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Confident Ruby: Be A Coding Hemingway