SlideShare a Scribd company logo
1 of 59
Understanding
TDD and Refactoring
with LEGO
Bryan Beecham
@BillyGarnet
90 minutes
Introduction
Exercise - 1


 Open up one LEGO packet
 Build a person and a house out of LEGO
Admire your work



Take a photo. Upload to Twitter. Brag to your friends.
Reference


Test-Driven
Development
By Example
Kent Beck
TDD



Clean code that works ~ Ron Jefferies
TDD


It is a predictable way to develop. You know when you
are finished, without having to worry about a long bug
trail
TDD


It gives you a chance to learn all of the lessons that the
code has to teach you. If you only slap together the first
thing you think of, then you never have time to think of
a second, better thing.
TDD



It improves the lives of the users of your software.
TDD



It lets your teammates count on you, and you on them.
TDD



It feels good to write it.
The Mantra
Red - Green - Refactor
photo from doolwind.com
The Mantra - Red



Write a small test that doesn’t work
The Mantra - Green



Do the minimum to make the test work
The Mantra - Refactor



Eliminate duplication
Exercise - 2



 Build a person and a house with TDD
Prepare your environment



Clear the area in front of you. This is your program.
First Test



 Does the person exist? No?
Hurray!!!
We failed the test!
Celebrate! High 5s!
Minimum to pass the test



Add a block. Can that be a person?
Hurray!!!


 The person now exists!
 Not very impressive but it could represent a person.
 We passed the test! We are rocking now!
Refactor



Remove any duplication. In this case we’re good.
Same thing for house


Blah, blah, awesome recreation by speaker...everyone
is extremely impressed and are thinking this might be
the best session of the whole conference.
We need a new test


The house is taller then the person.
Assert.IsTrue(house.height > person.height);
Hurray!!! -
More Failure
The person is the
same size so we fail
this test.
Well done!
Failure =
Learning Opportunity


If your not failing, your not learning.
Minimum to pass the test



From the audience this time. Anyone? Bueller?
Hurray!!! - Success



 Alright, we passed the test.
Refactor



Still very simple. Still nice and clean.
Software Requirements

Software must do three things:
  It must work
  It must be understandable
  It must be updatable
  (Robert C. Martin...I think)
We need a new test

Is the house wider then the person? No?
We failed another test! Awesome! We are learning a lot
about improvements that are needed to our code.
Let’s do the minimum to pass the test.
Any duplication to remove?
We need a new test

Can your person fit in the house? Yikes! No.
We failed another test! Awesome! We are learning so
much about what our customer needs.
Let’s do the minimum to pass the test.
Any duplication to remove?
Exercise - 3 Partners!

 Break into groups of
 two for this next
 exercise.
 When developers do
 this we call it Pair
 Programming
 Berkley photo from the web
New Requirements
Your new program needs to have:
  A person
  A house
  A tree
  An animal
  A vehicle
Let’s Practice!
 Work together to come up with some new tests
 Keep building to minimally pass tests
 Don’t worry about Refactoring for now
 Here’s a few if you get stuck:
   Is the house at least x inches/cm tall?
   Is the tree the same size as the house?
   Is the animal smaller than the person?
Review


Let’s take a few minutes to walk around and look at
everybody’s creations!
Taking breaks and stretching your muscles is very
important to stay healthy
Apology

You may have to break your wonderful new structures
for the components for the next section.
Don’t worry, there is more building to come!
Please do take a photo. Remember @BillyGarnet if your
tweeting about the amazing time your having!
Refactoring


Refactoring is the process of changing a software
system in such a way that it does not alter the external
behavior of the code yet improves its internal structure.
~Martin Fowler
LEGO Refactoring


We will be using big
bricks with two points
on top and panels with
two points on top.
Build our program


Stack up big (normal height) bricks like this:
brown-red-blue-blue-red-green-yellow-red-green
brown on top and green at the very bottom
Class and Methods


Your group of lego bricks represents a class
Each one of these colour bands represents a method
Duplication



 Notice how there are repeats of the same colour
 bands. This is duplication in our code. Let’s fix this!
Extract Method

We are going to start by extracting the method. We will
replace the first big red block with a small red panel.
Put the structure back together and put the big red
block on the bottom.
This small red panel simply tells the program to go to
run the big red block code.
Remove Duplication


Now let’s replace the other big red blocks with the flat
red panels.
We don’t need to move these big red blocks to the
bottom since we already have that code there.
Keep Going!


Let’s do (Extract Method) on that big blue section.
Even though it’s not repeated, it would be easier to
read the program with that blue blob at the bottom.
Audience Participation


 Can anyone see other duplication?
 Important Note: Consider Light and Dark Green the
 same colour for this exercise. (that was a hint btw)
Readability


 I really don’t like the way we are mixing big and flat
 pieces at the top of our program.
 Let’s extract brown and yellow as well
Clarity


 Remember one of the requirements for good software
 is that it’s easy to update.
 Let’s re-arrange these big bottom blocks to match the
 order of the flat panels that are above them.
Break
Stand up and stretch - really, it’s important
Exercise 4 -Team Build

Arrange yourself into groups of 4 or 5.
Each group will come up with a large structure to build.
You will be a software team, working in pairs,
contributing to a large structure (the build).
Decide on an idea


Shh...don’t tell the other tables.
(Jeopardy music...)
Break it into components

Take a minute to write out each of the components that
need to be built.
Each pair will have a few minutes to build their part
through TDD.
We will then add the sections to the big project. Make
sure they still pass the tests.
We will repeat this a few times
Demo time!


Each team will now present their creation.
Please share a few tests that you came up with.
Review

Test-Driven Development / Design
Refactoring
Pair Programming
A bit of developer speak
Questions?


Bryan Beecham
@BillyGarnet
bryan@icebergideas.com
No really, it’s over
There are no more slides
No trailers
Looking for more?


Check out http://www.humanrefactor.com
Soon to have lot’s of cool info there

More Related Content

Recently uploaded

Gripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to MissGripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to Missget joys
 
Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...
Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...
Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...Amil Baba Company
 
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa EscortsCash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa EscortsApsara Of India
 
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...First NO1 World Amil baba in Faisalabad
 
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCRdollysharma2066
 
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一lvtagr7
 
Call Girls Ellis Bridge 7397865700 Independent Call Girls
Call Girls Ellis Bridge 7397865700 Independent Call GirlsCall Girls Ellis Bridge 7397865700 Independent Call Girls
Call Girls Ellis Bridge 7397865700 Independent Call Girlsssuser7cb4ff
 
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts ServiceVIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts ServiceApsara Of India
 
fmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the heartsfmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the heartsa18205752
 
Taken Pilot Episode Story pitch Document
Taken Pilot Episode Story pitch DocumentTaken Pilot Episode Story pitch Document
Taken Pilot Episode Story pitch Documentf4ssvxpz62
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...Apsara Of India
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607dollysharma2066
 
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...Amil Baba Company
 
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full NightCall Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Nightssuser7cb4ff
 
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full NightCall Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
Call Girls Chorasi 7397865700 Ridhima Hire Me Full Night
Call Girls Chorasi 7397865700 Ridhima Hire Me Full NightCall Girls Chorasi 7397865700 Ridhima Hire Me Full Night
Call Girls Chorasi 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
Call Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full NightCall Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzersQUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzersSJU Quizzers
 

Recently uploaded (20)

Gripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to MissGripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to Miss
 
Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...
Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...
Amil Baba in karachi Kala jadu Expert Amil baba Black magic Specialist in Isl...
 
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa EscortsCash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
 
Call Girls Koti 7001305949 all area service COD available Any Time
Call Girls Koti 7001305949 all area service COD available Any TimeCall Girls Koti 7001305949 all area service COD available Any Time
Call Girls Koti 7001305949 all area service COD available Any Time
 
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
 
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
 
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
定制(UofT毕业证书)加拿大多伦多大学毕业证成绩单原版一比一
 
Call Girls Ellis Bridge 7397865700 Independent Call Girls
Call Girls Ellis Bridge 7397865700 Independent Call GirlsCall Girls Ellis Bridge 7397865700 Independent Call Girls
Call Girls Ellis Bridge 7397865700 Independent Call Girls
 
young call girls in Hari Nagar,🔝 9953056974 🔝 escort Service
young call girls in Hari Nagar,🔝 9953056974 🔝 escort Serviceyoung call girls in Hari Nagar,🔝 9953056974 🔝 escort Service
young call girls in Hari Nagar,🔝 9953056974 🔝 escort Service
 
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts ServiceVIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
VIP Call Girls In Goa 7028418221 Call Girls In Baga Beach Escorts Service
 
fmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the heartsfmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the hearts
 
Taken Pilot Episode Story pitch Document
Taken Pilot Episode Story pitch DocumentTaken Pilot Episode Story pitch Document
Taken Pilot Episode Story pitch Document
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
5* Hotel Call Girls In Goa 7028418221 Call Girls In Calangute Beach Escort Se...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
 
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
Amil baba in Pakistan amil baba Karachi amil baba in pakistan amil baba in la...
 
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full NightCall Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
Call Girls Prahlad Nagar 9920738301 Ridhima Hire Me Full Night
 
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full NightCall Girls SG Highway 7397865700 Ridhima Hire Me Full Night
Call Girls SG Highway 7397865700 Ridhima Hire Me Full Night
 
Call Girls Chorasi 7397865700 Ridhima Hire Me Full Night
Call Girls Chorasi 7397865700 Ridhima Hire Me Full NightCall Girls Chorasi 7397865700 Ridhima Hire Me Full Night
Call Girls Chorasi 7397865700 Ridhima Hire Me Full Night
 
Call Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full NightCall Girls Sanand 7397865700 Ridhima Hire Me Full Night
Call Girls Sanand 7397865700 Ridhima Hire Me Full Night
 
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzersQUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
QUIZ BOLLYWOOD ( weekly quiz ) - SJU quizzers
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

TDD and Refactoring with LEGO

  • 1. Understanding TDD and Refactoring with LEGO Bryan Beecham @BillyGarnet 90 minutes
  • 3. Exercise - 1 Open up one LEGO packet Build a person and a house out of LEGO
  • 4. Admire your work Take a photo. Upload to Twitter. Brag to your friends.
  • 6. TDD Clean code that works ~ Ron Jefferies
  • 7. TDD It is a predictable way to develop. You know when you are finished, without having to worry about a long bug trail
  • 8. TDD It gives you a chance to learn all of the lessons that the code has to teach you. If you only slap together the first thing you think of, then you never have time to think of a second, better thing.
  • 9. TDD It improves the lives of the users of your software.
  • 10. TDD It lets your teammates count on you, and you on them.
  • 11. TDD It feels good to write it.
  • 12. The Mantra Red - Green - Refactor photo from doolwind.com
  • 13. The Mantra - Red Write a small test that doesn’t work
  • 14. The Mantra - Green Do the minimum to make the test work
  • 15. The Mantra - Refactor Eliminate duplication
  • 16. Exercise - 2 Build a person and a house with TDD
  • 17. Prepare your environment Clear the area in front of you. This is your program.
  • 18. First Test Does the person exist? No?
  • 19. Hurray!!! We failed the test! Celebrate! High 5s!
  • 20. Minimum to pass the test Add a block. Can that be a person?
  • 21. Hurray!!! The person now exists! Not very impressive but it could represent a person. We passed the test! We are rocking now!
  • 22. Refactor Remove any duplication. In this case we’re good.
  • 23. Same thing for house Blah, blah, awesome recreation by speaker...everyone is extremely impressed and are thinking this might be the best session of the whole conference.
  • 24. We need a new test The house is taller then the person. Assert.IsTrue(house.height > person.height);
  • 25. Hurray!!! - More Failure The person is the same size so we fail this test. Well done!
  • 26. Failure = Learning Opportunity If your not failing, your not learning.
  • 27. Minimum to pass the test From the audience this time. Anyone? Bueller?
  • 28. Hurray!!! - Success Alright, we passed the test.
  • 29. Refactor Still very simple. Still nice and clean.
  • 30. Software Requirements Software must do three things: It must work It must be understandable It must be updatable (Robert C. Martin...I think)
  • 31. We need a new test Is the house wider then the person? No? We failed another test! Awesome! We are learning a lot about improvements that are needed to our code. Let’s do the minimum to pass the test. Any duplication to remove?
  • 32. We need a new test Can your person fit in the house? Yikes! No. We failed another test! Awesome! We are learning so much about what our customer needs. Let’s do the minimum to pass the test. Any duplication to remove?
  • 33. Exercise - 3 Partners! Break into groups of two for this next exercise. When developers do this we call it Pair Programming Berkley photo from the web
  • 34. New Requirements Your new program needs to have: A person A house A tree An animal A vehicle
  • 35. Let’s Practice! Work together to come up with some new tests Keep building to minimally pass tests Don’t worry about Refactoring for now Here’s a few if you get stuck: Is the house at least x inches/cm tall? Is the tree the same size as the house? Is the animal smaller than the person?
  • 36. Review Let’s take a few minutes to walk around and look at everybody’s creations! Taking breaks and stretching your muscles is very important to stay healthy
  • 37. Apology You may have to break your wonderful new structures for the components for the next section. Don’t worry, there is more building to come! Please do take a photo. Remember @BillyGarnet if your tweeting about the amazing time your having!
  • 38. Refactoring Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. ~Martin Fowler
  • 39. LEGO Refactoring We will be using big bricks with two points on top and panels with two points on top.
  • 40. Build our program Stack up big (normal height) bricks like this: brown-red-blue-blue-red-green-yellow-red-green brown on top and green at the very bottom
  • 41. Class and Methods Your group of lego bricks represents a class Each one of these colour bands represents a method
  • 42. Duplication Notice how there are repeats of the same colour bands. This is duplication in our code. Let’s fix this!
  • 43. Extract Method We are going to start by extracting the method. We will replace the first big red block with a small red panel. Put the structure back together and put the big red block on the bottom. This small red panel simply tells the program to go to run the big red block code.
  • 44. Remove Duplication Now let’s replace the other big red blocks with the flat red panels. We don’t need to move these big red blocks to the bottom since we already have that code there.
  • 45. Keep Going! Let’s do (Extract Method) on that big blue section. Even though it’s not repeated, it would be easier to read the program with that blue blob at the bottom.
  • 46. Audience Participation Can anyone see other duplication? Important Note: Consider Light and Dark Green the same colour for this exercise. (that was a hint btw)
  • 47. Readability I really don’t like the way we are mixing big and flat pieces at the top of our program. Let’s extract brown and yellow as well
  • 48. Clarity Remember one of the requirements for good software is that it’s easy to update. Let’s re-arrange these big bottom blocks to match the order of the flat panels that are above them.
  • 49. Break Stand up and stretch - really, it’s important
  • 50. Exercise 4 -Team Build Arrange yourself into groups of 4 or 5. Each group will come up with a large structure to build. You will be a software team, working in pairs, contributing to a large structure (the build).
  • 51. Decide on an idea Shh...don’t tell the other tables. (Jeopardy music...)
  • 52. Break it into components Take a minute to write out each of the components that need to be built. Each pair will have a few minutes to build their part through TDD. We will then add the sections to the big project. Make sure they still pass the tests. We will repeat this a few times
  • 53. Demo time! Each team will now present their creation. Please share a few tests that you came up with.
  • 54. Review Test-Driven Development / Design Refactoring Pair Programming A bit of developer speak
  • 57. There are no more slides
  • 59. Looking for more? Check out http://www.humanrefactor.com Soon to have lot’s of cool info there

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n