SlideShare a Scribd company logo
1 of 85
Download to read offline
Understanding
TDD and Refactoring
with LEGO
Bryan Beecham
@BillyGarnet
Mike Bowler
@mike_bowler
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
What is the goal of TDD?
It creates 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.
The perfect 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.
If 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
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?
New Requirements
Your new program needs to have:
A person
A house
A tree
An animal
A vehicle
Review
Let’s take a minute to walk around and look at
everybody’s creations!
Taking breaks and stretching your muscles (eyes, legs,
arms, back) 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 and
@mike_bowler 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
behaviour of the code yet improves its internal
structure.
~Martin Fowler
LEGO Refactoring
We will be using bricks
with two points on top
and panels with two
points on top.
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
Build our program
Your group of lego bricks represents a program.
Each one of these colour bands represents some logic
in your code.
Class and Methods
Duplication
Remember DRY (Don’t Repeat Yourself).
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 a 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?
Readability
I really don’t like the way we are mixing bricks and flat
panels at the top of our program.
Let’s extract brown and yellow as well (Composite
Method)
Clarity
Remember some of the requirements for good
software? It needs to be easy to read and update.
Let’s re-arrange these big bottom blocks to match the
order of the flat panels that are above them.
Super Fast Break
Stand up and stretch - really, it’s important!
Share something you’ve learned with a
neighbour!
Exercise 4 -Team Build
Each table will come up with a large structure with lots
of parts to build.
You will be a software team, working in pairs,
contributing to the large team structure (the build) at
Decide on an idea
Shh...don’t tell the other tables.
(Jeopardy music...)
Break it into components
Take a minute to write out a few of the components
that need to be built (product backlog).
Each pair will build a component through TDD.
We will then add the sections to the big project. Make
sure they don’t break the rest of the tests.
We will repeat this a few times.
Demo time!
A few teams will now present their creation.
Please share the tests that you came up with and point
out the solution.
Review
Test-Driven Development / Design
Refactoring
Pair Programming
A bit of developer speak
Experience working on a software team
Questions?
Bryan Beecham
@BillyGarnet
bbeecham@fusebill.com
Mike Bowler
@mike_bowler
mbowler@gargoylesoftware.com
Please separate the lego bricks into their respective
colours
TDD in Action!
If you would like to keep some LEGO, please stay and
we will divide it up into the packets that we started
with.
Success!
We have passed all tests! We can be confident that the
bags contain the right pieces.
No really, it’s over
There are no more slides
No trailers
Looking for more?
Check out http://www.billygar.net
Links to HumanRefactoring, and soon more LEGO!

More Related Content

Viewers also liked

Continuous Improvement
Continuous ImprovementContinuous Improvement
Continuous ImprovementJez Humble
 
Refactoring Fest
Refactoring FestRefactoring Fest
Refactoring FestNaresh Jain
 
DevOps Introduction
DevOps IntroductionDevOps Introduction
DevOps IntroductionRobert Sell
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101Adam Culp
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integrationdrluckyspin
 
Cidadania e meio ambiente
Cidadania e meio ambienteCidadania e meio ambiente
Cidadania e meio ambienteLuis Araujo
 
Oban Digital, Senior Strategist, Kezia Bibby 'Audience intent profiling in...
  Oban Digital, Senior Strategist, Kezia Bibby  'Audience intent profiling in...  Oban Digital, Senior Strategist, Kezia Bibby  'Audience intent profiling in...
Oban Digital, Senior Strategist, Kezia Bibby 'Audience intent profiling in...Oban International
 
Power Point Combas PIE LA RIOJA
Power Point Combas PIE LA RIOJAPower Point Combas PIE LA RIOJA
Power Point Combas PIE LA RIOJAANGELOLIVAN
 
Posicionament SEO, localització i visibilitat
Posicionament SEO, localització i visibilitat Posicionament SEO, localització i visibilitat
Posicionament SEO, localització i visibilitat Fundació Bit
 
Gracias Por El Futbol
Gracias Por El FutbolGracias Por El Futbol
Gracias Por El Futbolconillet
 
Diario Resumen 20161025
Diario Resumen 20161025Diario Resumen 20161025
Diario Resumen 20161025Diario Resumen
 

Viewers also liked (19)

Agile testing games
Agile testing gamesAgile testing games
Agile testing games
 
Bad Smell In Codes 1
Bad Smell In Codes 1Bad Smell In Codes 1
Bad Smell In Codes 1
 
DevOps game lego
DevOps game legoDevOps game lego
DevOps game lego
 
Continuous Improvement
Continuous ImprovementContinuous Improvement
Continuous Improvement
 
Refactoring Fest
Refactoring FestRefactoring Fest
Refactoring Fest
 
Introduction
IntroductionIntroduction
Introduction
 
DevOps Introduction
DevOps IntroductionDevOps Introduction
DevOps Introduction
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
 
Cidadania e meio ambiente
Cidadania e meio ambienteCidadania e meio ambiente
Cidadania e meio ambiente
 
Oban Digital, Senior Strategist, Kezia Bibby 'Audience intent profiling in...
  Oban Digital, Senior Strategist, Kezia Bibby  'Audience intent profiling in...  Oban Digital, Senior Strategist, Kezia Bibby  'Audience intent profiling in...
Oban Digital, Senior Strategist, Kezia Bibby 'Audience intent profiling in...
 
Power Point Combas PIE LA RIOJA
Power Point Combas PIE LA RIOJAPower Point Combas PIE LA RIOJA
Power Point Combas PIE LA RIOJA
 
Posicionament SEO, localització i visibilitat
Posicionament SEO, localització i visibilitat Posicionament SEO, localització i visibilitat
Posicionament SEO, localització i visibilitat
 
Ppt patience
Ppt patiencePpt patience
Ppt patience
 
Catalogo true graphics
Catalogo true graphics Catalogo true graphics
Catalogo true graphics
 
Gracias Por El Futbol
Gracias Por El FutbolGracias Por El Futbol
Gracias Por El Futbol
 
Catálogo Map Impresores
Catálogo Map ImpresoresCatálogo Map Impresores
Catálogo Map Impresores
 
Tipus de mercats. Sara Alabort i Rossanna Gomar
Tipus de mercats. Sara Alabort i Rossanna GomarTipus de mercats. Sara Alabort i Rossanna Gomar
Tipus de mercats. Sara Alabort i Rossanna Gomar
 
Diario Resumen 20161025
Diario Resumen 20161025Diario Resumen 20161025
Diario Resumen 20161025
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

TDD and Refactoring with LEGO at Agile2013

  • 1. Understanding TDD and Refactoring with LEGO Bryan Beecham @BillyGarnet Mike Bowler @mike_bowler
  • 2. Exercise - 1 Open up one LEGO packet Build a person and a house out of LEGO
  • 3. Admire your work Take a photo. Upload to Twitter. Brag to your friends.
  • 5. What is the goal of TDD? It creates clean code that works ~ Ron Jefferies
  • 6. TDD It is a predictable way to develop. You know when you are finished, without having to worry about a long bug trail.
  • 7. 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.
  • 8. TDD It improves the lives of the users of your software.
  • 9. TDD It lets your teammates count on you, and you on them.
  • 10. TDD It feels good to write it.
  • 11. The Mantra Red - Green - Refactor photo from doolwind.com
  • 12. The Mantra - Red Write a small test that doesn’t work
  • 13. The Mantra - Green Do the minimum to make the test work
  • 14. The Mantra - Refactor Eliminate duplication
  • 15. Exercise - 2 Build a person and a house with TDD
  • 16. Prepare your environment Clear the area in front of you. This is your program. The perfect program!
  • 17. First Test Does the person exist? No?
  • 18. Hurray!!! We failed the test! Celebrate! High 5s!
  • 19. Minimum to pass the test Add a block. Can that be a person?
  • 20. Hurray!!! The person now exists! Not very impressive but it could represent a person. We passed the test! We are rocking now!
  • 21. Refactor Remove any duplication. In this case we’re good.
  • 22. 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.
  • 23. We need a new test The house is taller then the person. Assert.IsTrue(house.height > person.height);
  • 24. Hurray!!! - More Failure The person is the same size so we fail this test. Well done!
  • 25. Failure = Learning Opportunity If your not failing, your not learning. If your not learning...
  • 26. Minimum to pass the test From the audience this time. Anyone? Bueller?
  • 27. Hurray!!! - Success Alright, we passed the test.
  • 28. Refactor Still very simple. Still nice and clean.
  • 29. Software Requirements Software must do three things: It must work It must be understandable It must be updatable
  • 30. 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?
  • 31. 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?
  • 32. 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
  • 33. New Requirements Your new program needs to have: A person A house A tree An animal A vehicle
  • 34. 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?
  • 35. New Requirements Your new program needs to have: A person A house A tree An animal A vehicle
  • 36. Review Let’s take a minute to walk around and look at everybody’s creations! Taking breaks and stretching your muscles (eyes, legs, arms, back) 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 and @mike_bowler 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 behaviour of the code yet improves its internal structure. ~Martin Fowler
  • 39. LEGO Refactoring We will be using bricks with two points on top and panels with two points on top.
  • 40. 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 Build our program
  • 41. Your group of lego bricks represents a program. Each one of these colour bands represents some logic in your code. Class and Methods
  • 42. Duplication Remember DRY (Don’t Repeat Yourself). 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 a 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?
  • 47. Readability I really don’t like the way we are mixing bricks and flat panels at the top of our program. Let’s extract brown and yellow as well (Composite Method)
  • 48. Clarity Remember some of the requirements for good software? It needs to be easy to read and update. Let’s re-arrange these big bottom blocks to match the order of the flat panels that are above them.
  • 49. Super Fast Break Stand up and stretch - really, it’s important! Share something you’ve learned with a neighbour!
  • 50. Exercise 4 -Team Build Each table will come up with a large structure with lots of parts to build. You will be a software team, working in pairs, contributing to the large team structure (the build) at
  • 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 a few of the components that need to be built (product backlog). Each pair will build a component through TDD. We will then add the sections to the big project. Make sure they don’t break the rest of the tests. We will repeat this a few times.
  • 53. Demo time! A few teams will now present their creation. Please share the tests that you came up with and point out the solution.
  • 54. Review Test-Driven Development / Design Refactoring Pair Programming A bit of developer speak Experience working on a software team
  • 56. TDD in Action! If you would like to keep some LEGO, please stay and we will divide it up into the packets that we started with.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81. Success! We have passed all tests! We can be confident that the bags contain the right pieces.
  • 83. There are no more slides
  • 85. Looking for more? Check out http://www.billygar.net Links to HumanRefactoring, and soon more LEGO!