SlideShare une entreprise Scribd logo
1  sur  88
Advanced Ruby Idioms So Clean
You Can Eat Off Of Them
Brian Guthrie
bguthrie@thoughtworks.com
http://twitter.com/bguthrie
What this talk is about
“magic”
http://www.flickr.com/photos/cayusa/2962437091/
encouraging you to try things
preventing you from poking
yourself with the sharp end of a
         pointed stick
magic
magic
technical understanding
design maturity
What this talk is not about
trying to stop you
explaining why
Who this talk is for
Who this talk is for




0-6 months   6-12 months    12-36 months   36+ months
Who this talk is for




0-6 months     6-12 months    12-36 months   36+ months
     total
  noob sauce
Who this talk is for




0-6 months     6-12 months    12-36 months         36+ months
     total                                     hardened
  noob sauce                                 ruby veteran
Who this talk is for




0-6 months     6-12 months              12-36 months         36+ months
     total       a danger to yourself                    hardened
  noob sauce         and others                        ruby veteran
Who this talk is for




0-6 months     6-12 months              12-36 months         36+ months
     total       a danger to yourself                    hardened
  noob sauce         and others                        ruby veteran




                You know who you are.
Who this talk is for




0-6 months     6-12 months                  12-36 months       36+ months
     total                                             thick controllers
                 total lack of curiousity
  noob sauce                                          (total noob sauce)
ask questions anytime
           http://www.flickr.com/photos/jonnya/4212907371/
task:
build a custom validation framework
task:
build a custom validation framework
            a danger to yourself
                and others
Tip

Offload the heavy stuff to dedicated objects.
                 It’s worth the trouble.
Tip

Make sure your subclasses honor the behavior
            of their superclasses.
                 It’s worth the trouble.
a brief detour
   http://www.flickr.com/photos/garyseven/4434835473/
6
  (acceptable)
    types of
      Ruby
method signatures
0
1
2
{}
1{}
*
0 1 2 H 1H *
0 1 2 ... n
H 1H *
Tip

Stick to the Six Acceptable Ruby Method Signatures.
                      0, 1, 2, H, 1H, *
a danger to yourself
    and others
Tip

       Add behavior with
instance_eval or define_method,
      not method_missing.
http://www.flickr.com/photos/suneko/389852016/
                                                +
                                                http://www.flickr.com/photos/contusion/4066189755/
validations anywhere!
>> Object.new.method :valid?
=> #<Method: Object#valid?>
>> Object.new.method :valid?
=> #<Method: Object(BrianRecord::Extensions::Validations::InstanceMethods)#valid?>
Tip

Modularize and name any extensions you build.
           Some poor sucker, like me, has to maintain that thing.
Tip

Use self.included to leverage existing class behaviors.
                      Purely my own opinion.
a_very_bad_gem/lib/extensions/object/tap.rb
Tip

         Extend respectfully:
Check for competing implementations.
          Or I will hunt you down and slay you.
Tip

Write tests.
Write tests.
Write tests.
Write tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
YUM
RUBY WILL EAT YOU


 YUM
http://www.flickr.com/photos/pandiyan/146700348/
http://www.flickr.com/photos/bunchofpants/52816417/
Brian Guthrie
bguthrie@thoughtworks.com
http://twitter.com/bguthrie

questions?

Contenu connexe

En vedette

Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
IELTS Training - Misused Phrases in the IELTS Writing/ Speaking
IELTS Training - Misused Phrases in the IELTS Writing/ SpeakingIELTS Training - Misused Phrases in the IELTS Writing/ Speaking
IELTS Training - Misused Phrases in the IELTS Writing/ SpeakingJROOZ Review Center
 
Phrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntaxPhrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntaxMuhamad Umar Chatab
 
English idioms
English idiomsEnglish idioms
English idiomssnowmaid
 
How to Teach Yourself to Code
How to Teach Yourself to CodeHow to Teach Yourself to Code
How to Teach Yourself to CodeMattan Griffel
 
Speaking English (Linking Words)
Speaking English  (Linking Words)Speaking English  (Linking Words)
Speaking English (Linking Words)sandeep J
 
Useful phrases for speaking
Useful phrases for speakingUseful phrases for speaking
Useful phrases for speakingandydei
 
Ppt on World Of Smartphones
Ppt on World Of SmartphonesPpt on World Of Smartphones
Ppt on World Of SmartphonesPulkit Syal
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java DevelopersRobert Reiz
 
The Noun Phrase - Power up your description - Writing skills
The Noun Phrase - Power up your description - Writing skillsThe Noun Phrase - Power up your description - Writing skills
The Noun Phrase - Power up your description - Writing skillsKinga Brady
 
Sense relations & Semantics
Sense relations & SemanticsSense relations & Semantics
Sense relations & SemanticsAfuza Shara
 

En vedette (14)

Idioms
IdiomsIdioms
Idioms
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
English Idioms
English IdiomsEnglish Idioms
English Idioms
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
IELTS Training - Misused Phrases in the IELTS Writing/ Speaking
IELTS Training - Misused Phrases in the IELTS Writing/ SpeakingIELTS Training - Misused Phrases in the IELTS Writing/ Speaking
IELTS Training - Misused Phrases in the IELTS Writing/ Speaking
 
Phrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntaxPhrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntax
 
English idioms
English idiomsEnglish idioms
English idioms
 
How to Teach Yourself to Code
How to Teach Yourself to CodeHow to Teach Yourself to Code
How to Teach Yourself to Code
 
Speaking English (Linking Words)
Speaking English  (Linking Words)Speaking English  (Linking Words)
Speaking English (Linking Words)
 
Useful phrases for speaking
Useful phrases for speakingUseful phrases for speaking
Useful phrases for speaking
 
Ppt on World Of Smartphones
Ppt on World Of SmartphonesPpt on World Of Smartphones
Ppt on World Of Smartphones
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
The Noun Phrase - Power up your description - Writing skills
The Noun Phrase - Power up your description - Writing skillsThe Noun Phrase - Power up your description - Writing skills
The Noun Phrase - Power up your description - Writing skills
 
Sense relations & Semantics
Sense relations & SemanticsSense relations & Semantics
Sense relations & Semantics
 

Dernier

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Dernier (20)

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Advanced Ruby Idioms So Clean You Can Eat Off Of Them

Notes de l'éditeur

  1. tragically, a repeat offender as a framework writer I&amp;#x2019;m that guy; I just go write frameworks
  2. Look, you&apos;re going to go write a bunch of weird, crazy, and quite possibly criminally insane code in Ruby at some point or another in your career. Maybe you already have. I can&apos;t stop you, and I&apos;d be disappointed if you didn&apos;t at least try, so in this talk I&apos;ll show you how to do it without poking your own eye out with the pointy end of a sharpened stick.
  3. Explaining why you&amp;#x2019;d want to do these things Discouraging you from trying
  4. Look, you&apos;re going to go write a bunch of weird, crazy, and quite possibly criminally insane code in Ruby at some point or another in your career. Maybe you already have. I can&apos;t stop you, and I&apos;d be disappointed if you didn&apos;t at least try, so in this talk I&apos;ll show you how to do it without poking your own eye out with the pointy end of a sharpened stick.
  5. introduction; this is our goal; goals are important with DSLs
  6. simple lambda, no use of options
  7. slow, have to implement respond_to, have to call super, fairly complicated
  8. a little bit faster, still not exactly clear what&amp;#x2019;s going on
  9. faster yet, no memory leaks, a little bit clearer what&amp;#x2019;s going on--not EXACTLY rails convention
  10. a bad use of open classes, but even if good, there&amp;#x2019;s a problem
  11. Ruby is the name of the crocodile.
  12. Smart devs - obligation to team to condense &amp; beautify &amp; DRY out most commonly-used idioms Refactor and metaprogram more to domain, less to infrastructure
  13. Never again.