SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Selected Sessions from
    RailsConf 2007
   Jerry Richardson, jerry@jerryr.com
       Chief Technologist, iBlinkink
Clean Code

•    incremental improvement
    • always check code in better than you checked it out
    • never let the sun set on bad code
    • test first => quot;test obsessedquot;
     •  provides the necessary flexibility
Robert Martin
“I am not allowed to make a
   change that breaks the
 system. Every tiny change I
 make will keep that system
          working.”
Let’s Refactor

• Principle of least surprise
• tiny steps => change each variable type, then run the
  tests
• shrink the granularity of your development
• create a barrier between things that change and things
  that don't
Is it worth it?
• crafting good solutions
• clean it up as soon as it gets messy => the dinner
  parable: get up and walk away from the dinner table or
  keep your dishes clean all the time
• bad schedules, requirements, team dynamics can all be
  fixed but bad code rots, ferments and becomes an
  inexorable weight that drags the team down.
Professional Behavior
•   The quot;Green Bandquot;
• Professionals write their tests first
• Professionals keep their code clean
• Professionals know that the only way to go fast is to go
    well.
•   making things a little bit nicer => the check-in rule
Doing REST Right
Recognize rest principles in what you're
  already doing. Apply them to your
            whole process.
Orthodoxy (right teaching, right beliefs,
  right thoughts) versus Orthopraxy
            (right practice)
Orthodoxy
• Roy Fielding's Thesis defined REST (Representational
  State Transfer)
• All models are wrong but some are useful. - George
  Box
• Leaky Abstractions
• Diagrams are wrong but useful in representing
  complex, real-world systems. Same thing with
  abstractions.
REST isn’t...
• Pretty URLs
• CRUD
• respond_to
• map.resources
• a protocol - http
• an architecture
REST is...
• the architectural style of the web
•   Roy Fielding's Hierarchy
  • Abstract => Communication Theory
  •                REST
  •                Web Architecture
  •  Concrete => Implementation
REST is...
• A resource is anything that can be named
• A resource is an object with a couple of contraints -
  can only implement a very small number of methods,
  same for all resources
• you don't access a resource -- you access a
  representation of it. (respond_to with format.xml,
  format.txt, etc.)
Orthopraxy
• Identification - URL
• Interaction (Method or Verb)
  • Safety - has no side effects, incurs no obligations (get
    is the only method that is safe by definition)
 • idempotent -- applying a function once returns the
    same value as applying it multiple times (get, put and
    delete)
Post


• post is neither safe nor idempotent => reserve it for
  when you need it
Content, Body of Request
• REST pushes all of the complexity into content, out of
  identification and interaction
• messages should be use standards and be self-
  descriptive, like html
• look for content types that map to your application
  domain - instead of to_xml, use an established type for
  users => do vcard instead of your arbitrary user xml
Adding Tests to
Legacy Rails Apps
 Most first-time Rails apps are built
before a developer understands their
importance. Testing is painful in many
frameworks and ignored when many
    people switch to using rails.
Starting

• Don't do it all at once. It won't work.
• first, run rake
  • mysqladmin -u root create appname_test
• Use Migrations
•  Scaffolding is broken => those tests don't work.
One Step at a Time
• find a bug, write a test
• refactor a method, write a test
• treat each method as a box - don't get pulled in to
  testing everything
• test one thing at a time
• Test: what goes in? what comes out? (returning
  something in the method)
Rake or Direct Testing

• rake or direct testing
 • rake testing: rake test:uncommitted
 • direct: ruby test_file.rb -n test_name to run one test
    in a specific file
Build Tests from Logs


• Parameters then reproduce actual requests.
What To Test

• right response code
• correct template
• variable assignment
• assignment of desired object
Me.




      Questions?
Image Credits
•   DHH
    http://flickr.com/photos/x180/503574487/

•   Robert Martin
    http://flickr.com/photos/x180/503608084/

•   Scott Raymond
    http://flickr.com/photos/keeg/511239686/

•   Evan (Rabble) Henshaw-Plath
    http://flickr.com/photos/x180/474128166/

•   Me
    http://flickr.com/photos/jackdanger/502998700/

Mais conteúdo relacionado

Semelhante a Selected Sessions from RailsConf 2007

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguy_davis
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestDenim Group
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsRobert Glaser
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD WorkshopWolfram Arnold
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth PresentationLong Nguyen
 
Better Perl Practices
Better Perl PracticesBetter Perl Practices
Better Perl PracticesJay Shirley
 
Better Testing Through Behaviour
Better Testing Through BehaviourBetter Testing Through Behaviour
Better Testing Through BehaviourTom Adams
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development IntroductionNguyen Hai
 
BDD & Rspec
BDD & Rspec BDD & Rspec
BDD & Rspec Robbert
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecGiulio De Donato
 
Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8Mario Heiderich
 
Working With People Adl Uni
Working With People Adl UniWorking With People Adl Uni
Working With People Adl UniMatthew Landauer
 
Rails Conf Europe 2007 Notes
Rails Conf  Europe 2007  NotesRails Conf  Europe 2007  Notes
Rails Conf Europe 2007 NotesRoss Lawley
 
The Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With RubyThe Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With Rubymattmatt
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Coursepeter_marklund
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 

Semelhante a Selected Sessions from RailsConf 2007 (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On Rails
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
 
Better Perl Practices
Better Perl PracticesBetter Perl Practices
Better Perl Practices
 
React performance
React performanceReact performance
React performance
 
Better Testing Through Behaviour
Better Testing Through BehaviourBetter Testing Through Behaviour
Better Testing Through Behaviour
 
Becoming A Php Ninja
Becoming A Php NinjaBecoming A Php Ninja
Becoming A Php Ninja
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Mlw
MlwMlw
Mlw
 
BDD & Rspec
BDD & Rspec BDD & Rspec
BDD & Rspec
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
 
Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8
 
Working With People Adl Uni
Working With People Adl UniWorking With People Adl Uni
Working With People Adl Uni
 
Rails Conf Europe 2007 Notes
Rails Conf  Europe 2007  NotesRails Conf  Europe 2007  Notes
Rails Conf Europe 2007 Notes
 
The Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With RubyThe Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With Ruby
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 

Último

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
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
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"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
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Último (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"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
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

Selected Sessions from RailsConf 2007

  • 1. Selected Sessions from RailsConf 2007 Jerry Richardson, jerry@jerryr.com Chief Technologist, iBlinkink
  • 2. Clean Code • incremental improvement • always check code in better than you checked it out • never let the sun set on bad code • test first => quot;test obsessedquot; • provides the necessary flexibility
  • 3. Robert Martin “I am not allowed to make a change that breaks the system. Every tiny change I make will keep that system working.”
  • 4. Let’s Refactor • Principle of least surprise • tiny steps => change each variable type, then run the tests • shrink the granularity of your development • create a barrier between things that change and things that don't
  • 5. Is it worth it? • crafting good solutions • clean it up as soon as it gets messy => the dinner parable: get up and walk away from the dinner table or keep your dishes clean all the time • bad schedules, requirements, team dynamics can all be fixed but bad code rots, ferments and becomes an inexorable weight that drags the team down.
  • 6. Professional Behavior • The quot;Green Bandquot; • Professionals write their tests first • Professionals keep their code clean • Professionals know that the only way to go fast is to go well. • making things a little bit nicer => the check-in rule
  • 7. Doing REST Right Recognize rest principles in what you're already doing. Apply them to your whole process. Orthodoxy (right teaching, right beliefs, right thoughts) versus Orthopraxy (right practice)
  • 8. Orthodoxy • Roy Fielding's Thesis defined REST (Representational State Transfer) • All models are wrong but some are useful. - George Box • Leaky Abstractions • Diagrams are wrong but useful in representing complex, real-world systems. Same thing with abstractions.
  • 9. REST isn’t... • Pretty URLs • CRUD • respond_to • map.resources • a protocol - http • an architecture
  • 10. REST is... • the architectural style of the web • Roy Fielding's Hierarchy • Abstract => Communication Theory • REST • Web Architecture • Concrete => Implementation
  • 11. REST is... • A resource is anything that can be named • A resource is an object with a couple of contraints - can only implement a very small number of methods, same for all resources • you don't access a resource -- you access a representation of it. (respond_to with format.xml, format.txt, etc.)
  • 12. Orthopraxy • Identification - URL • Interaction (Method or Verb) • Safety - has no side effects, incurs no obligations (get is the only method that is safe by definition) • idempotent -- applying a function once returns the same value as applying it multiple times (get, put and delete)
  • 13. Post • post is neither safe nor idempotent => reserve it for when you need it
  • 14. Content, Body of Request • REST pushes all of the complexity into content, out of identification and interaction • messages should be use standards and be self- descriptive, like html • look for content types that map to your application domain - instead of to_xml, use an established type for users => do vcard instead of your arbitrary user xml
  • 15. Adding Tests to Legacy Rails Apps Most first-time Rails apps are built before a developer understands their importance. Testing is painful in many frameworks and ignored when many people switch to using rails.
  • 16. Starting • Don't do it all at once. It won't work. • first, run rake • mysqladmin -u root create appname_test • Use Migrations • Scaffolding is broken => those tests don't work.
  • 17. One Step at a Time • find a bug, write a test • refactor a method, write a test • treat each method as a box - don't get pulled in to testing everything • test one thing at a time • Test: what goes in? what comes out? (returning something in the method)
  • 18. Rake or Direct Testing • rake or direct testing • rake testing: rake test:uncommitted • direct: ruby test_file.rb -n test_name to run one test in a specific file
  • 19. Build Tests from Logs • Parameters then reproduce actual requests.
  • 20. What To Test • right response code • correct template • variable assignment • assignment of desired object
  • 21. Me. Questions?
  • 22. Image Credits • DHH http://flickr.com/photos/x180/503574487/ • Robert Martin http://flickr.com/photos/x180/503608084/ • Scott Raymond http://flickr.com/photos/keeg/511239686/ • Evan (Rabble) Henshaw-Plath http://flickr.com/photos/x180/474128166/ • Me http://flickr.com/photos/jackdanger/502998700/