Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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
t...
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 n...
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 mig...
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 im...
We need a new test
Can your person fit in the house? Yikes! No.
We failed another test! Awesome! We are learning so
much ab...
Exercise - 3 Partners!
Break into groups of
two for this next
exercise.
When developers do
this we call it Pair
Programmin...
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 Refac...
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 (ey...
Apology
You may have to break your wonderful new structures
for the components for the next section.
Don’t worry, there is...
Refactoring
Refactoring is the process of changing a software
system in such a way that it does not alter the external
beh...
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
t...
Your group of lego bricks represents a program.
Each one of these colour bands represents some logic
in your code.
Class a...
Duplication
Remember DRY (Don’t Repeat Yourself).
Notice how there are repeats of the same colour
bands. This is duplicati...
Extract Method
We are going to start by extracting a method. We will
replace the first big red block with a small red panel...
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...
Keep Going!
Let’s do (Extract Method) on that big blue section.
Even though it’s not repeated, it would be easier to
read ...
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...
Clarity
Remember some of the requirements for good
software? It needs to be easy to read and update.
Let’s re-arrange thes...
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 ...
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 ...
Demo time!
A few teams will now present their creation.
Please share the tests that you came up with and point
out the sol...
Review
Test-Driven Development / Design
Refactoring
Pair Programming
A bit of developer speak
Experience working on a soft...
Questions?
Bryan Beecham
@BillyGarnet
bbeecham@fusebill.com
Mike Bowler
@mike_bowler
mbowler@gargoylesoftware.com
Please s...
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
...
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!
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
TDD and Refactoring with LEGO at Agile2013
Upcoming SlideShare
Loading in …5
×

of

TDD and Refactoring with LEGO at Agile2013 Slide 1 TDD and Refactoring with LEGO at Agile2013 Slide 2 TDD and Refactoring with LEGO at Agile2013 Slide 3 TDD and Refactoring with LEGO at Agile2013 Slide 4 TDD and Refactoring with LEGO at Agile2013 Slide 5 TDD and Refactoring with LEGO at Agile2013 Slide 6 TDD and Refactoring with LEGO at Agile2013 Slide 7 TDD and Refactoring with LEGO at Agile2013 Slide 8 TDD and Refactoring with LEGO at Agile2013 Slide 9 TDD and Refactoring with LEGO at Agile2013 Slide 10 TDD and Refactoring with LEGO at Agile2013 Slide 11 TDD and Refactoring with LEGO at Agile2013 Slide 12 TDD and Refactoring with LEGO at Agile2013 Slide 13 TDD and Refactoring with LEGO at Agile2013 Slide 14 TDD and Refactoring with LEGO at Agile2013 Slide 15 TDD and Refactoring with LEGO at Agile2013 Slide 16 TDD and Refactoring with LEGO at Agile2013 Slide 17 TDD and Refactoring with LEGO at Agile2013 Slide 18 TDD and Refactoring with LEGO at Agile2013 Slide 19 TDD and Refactoring with LEGO at Agile2013 Slide 20 TDD and Refactoring with LEGO at Agile2013 Slide 21 TDD and Refactoring with LEGO at Agile2013 Slide 22 TDD and Refactoring with LEGO at Agile2013 Slide 23 TDD and Refactoring with LEGO at Agile2013 Slide 24 TDD and Refactoring with LEGO at Agile2013 Slide 25 TDD and Refactoring with LEGO at Agile2013 Slide 26 TDD and Refactoring with LEGO at Agile2013 Slide 27 TDD and Refactoring with LEGO at Agile2013 Slide 28 TDD and Refactoring with LEGO at Agile2013 Slide 29 TDD and Refactoring with LEGO at Agile2013 Slide 30 TDD and Refactoring with LEGO at Agile2013 Slide 31 TDD and Refactoring with LEGO at Agile2013 Slide 32 TDD and Refactoring with LEGO at Agile2013 Slide 33 TDD and Refactoring with LEGO at Agile2013 Slide 34 TDD and Refactoring with LEGO at Agile2013 Slide 35 TDD and Refactoring with LEGO at Agile2013 Slide 36 TDD and Refactoring with LEGO at Agile2013 Slide 37 TDD and Refactoring with LEGO at Agile2013 Slide 38 TDD and Refactoring with LEGO at Agile2013 Slide 39 TDD and Refactoring with LEGO at Agile2013 Slide 40 TDD and Refactoring with LEGO at Agile2013 Slide 41 TDD and Refactoring with LEGO at Agile2013 Slide 42 TDD and Refactoring with LEGO at Agile2013 Slide 43 TDD and Refactoring with LEGO at Agile2013 Slide 44 TDD and Refactoring with LEGO at Agile2013 Slide 45 TDD and Refactoring with LEGO at Agile2013 Slide 46 TDD and Refactoring with LEGO at Agile2013 Slide 47 TDD and Refactoring with LEGO at Agile2013 Slide 48 TDD and Refactoring with LEGO at Agile2013 Slide 49 TDD and Refactoring with LEGO at Agile2013 Slide 50 TDD and Refactoring with LEGO at Agile2013 Slide 51 TDD and Refactoring with LEGO at Agile2013 Slide 52 TDD and Refactoring with LEGO at Agile2013 Slide 53 TDD and Refactoring with LEGO at Agile2013 Slide 54 TDD and Refactoring with LEGO at Agile2013 Slide 55 TDD and Refactoring with LEGO at Agile2013 Slide 56 TDD and Refactoring with LEGO at Agile2013 Slide 57 TDD and Refactoring with LEGO at Agile2013 Slide 58 TDD and Refactoring with LEGO at Agile2013 Slide 59 TDD and Refactoring with LEGO at Agile2013 Slide 60 TDD and Refactoring with LEGO at Agile2013 Slide 61 TDD and Refactoring with LEGO at Agile2013 Slide 62 TDD and Refactoring with LEGO at Agile2013 Slide 63 TDD and Refactoring with LEGO at Agile2013 Slide 64 TDD and Refactoring with LEGO at Agile2013 Slide 65 TDD and Refactoring with LEGO at Agile2013 Slide 66 TDD and Refactoring with LEGO at Agile2013 Slide 67 TDD and Refactoring with LEGO at Agile2013 Slide 68 TDD and Refactoring with LEGO at Agile2013 Slide 69 TDD and Refactoring with LEGO at Agile2013 Slide 70 TDD and Refactoring with LEGO at Agile2013 Slide 71 TDD and Refactoring with LEGO at Agile2013 Slide 72 TDD and Refactoring with LEGO at Agile2013 Slide 73 TDD and Refactoring with LEGO at Agile2013 Slide 74 TDD and Refactoring with LEGO at Agile2013 Slide 75 TDD and Refactoring with LEGO at Agile2013 Slide 76 TDD and Refactoring with LEGO at Agile2013 Slide 77 TDD and Refactoring with LEGO at Agile2013 Slide 78 TDD and Refactoring with LEGO at Agile2013 Slide 79 TDD and Refactoring with LEGO at Agile2013 Slide 80 TDD and Refactoring with LEGO at Agile2013 Slide 81 TDD and Refactoring with LEGO at Agile2013 Slide 82 TDD and Refactoring with LEGO at Agile2013 Slide 83 TDD and Refactoring with LEGO at Agile2013 Slide 84 TDD and Refactoring with LEGO at Agile2013 Slide 85
Upcoming SlideShare
User Research
Next
Download to read offline and view in fullscreen.

12 Likes

Share

Download to read offline

TDD and Refactoring with LEGO at Agile2013

Download to read offline

This is a session to teach test driven development / design. It has been presented in various cities throughout North America. This is the final slides from the Agile 2013 conference in Nashville. Now includes all bricks you need to build your own kits.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

TDD and Refactoring with LEGO at Agile2013

  1. 1. Understanding TDD and Refactoring with LEGO Bryan Beecham @BillyGarnet Mike Bowler @mike_bowler
  2. 2. Exercise - 1 Open up one LEGO packet Build a person and a house out of LEGO
  3. 3. Admire your work Take a photo. Upload to Twitter. Brag to your friends.
  4. 4. Reference Test-Driven Development By Example Kent Beck
  5. 5. What is the goal of TDD? It creates clean code that works ~ Ron Jefferies
  6. 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. 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. 8. TDD It improves the lives of the users of your software.
  9. 9. TDD It lets your teammates count on you, and you on them.
  10. 10. TDD It feels good to write it.
  11. 11. The Mantra Red - Green - Refactor photo from doolwind.com
  12. 12. The Mantra - Red Write a small test that doesn’t work
  13. 13. The Mantra - Green Do the minimum to make the test work
  14. 14. The Mantra - Refactor Eliminate duplication
  15. 15. Exercise - 2 Build a person and a house with TDD
  16. 16. Prepare your environment Clear the area in front of you. This is your program. The perfect program!
  17. 17. First Test Does the person exist? No?
  18. 18. Hurray!!! We failed the test! Celebrate! High 5s!
  19. 19. Minimum to pass the test Add a block. Can that be a person?
  20. 20. Hurray!!! The person now exists! Not very impressive but it could represent a person. We passed the test! We are rocking now!
  21. 21. Refactor Remove any duplication. In this case we’re good.
  22. 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. 23. We need a new test The house is taller then the person. Assert.IsTrue(house.height > person.height);
  24. 24. Hurray!!! - More Failure The person is the same size so we fail this test. Well done!
  25. 25. Failure = Learning Opportunity If your not failing, your not learning. If your not learning...
  26. 26. Minimum to pass the test From the audience this time. Anyone? Bueller?
  27. 27. Hurray!!! - Success Alright, we passed the test.
  28. 28. Refactor Still very simple. Still nice and clean.
  29. 29. Software Requirements Software must do three things: It must work It must be understandable It must be updatable
  30. 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. 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. 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. 33. New Requirements Your new program needs to have: A person A house A tree An animal A vehicle
  34. 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. 35. New Requirements Your new program needs to have: A person A house A tree An animal A vehicle
  36. 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. 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. 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. 39. LEGO Refactoring We will be using bricks with two points on top and panels with two points on top.
  40. 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. 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. 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. 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. 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. 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. 46. Audience Participation Can anyone see other duplication?
  47. 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. 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. 49. Super Fast Break Stand up and stretch - really, it’s important! Share something you’ve learned with a neighbour!
  50. 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. 51. Decide on an idea Shh...don’t tell the other tables. (Jeopardy music...)
  52. 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. 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. 54. Review Test-Driven Development / Design Refactoring Pair Programming A bit of developer speak Experience working on a software team
  55. 55. Questions? Bryan Beecham @BillyGarnet bbeecham@fusebill.com Mike Bowler @mike_bowler mbowler@gargoylesoftware.com Please separate the lego bricks into their respective colours
  56. 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. 57. Success! We have passed all tests! We can be confident that the bags contain the right pieces.
  58. 58. No really, it’s over
  59. 59. There are no more slides
  60. 60. No trailers
  61. 61. Looking for more? Check out http://www.billygar.net Links to HumanRefactoring, and soon more LEGO!
  • ssuserefac70

    Nov. 7, 2019
  • fabiuz

    Sep. 13, 2019
  • nrgomes

    May. 8, 2019
  • LettoMV

    Mar. 27, 2015
  • chileagil

    Mar. 21, 2015
  • saager

    Jul. 28, 2014
  • jonmjorgensen

    Jul. 3, 2014
  • arditakaraj

    Oct. 23, 2013
  • choldorf

    Aug. 21, 2013
  • greeneyesco

    Aug. 13, 2013
  • christianlinck583

    Aug. 12, 2013
  • powerirs

    Aug. 11, 2013

This is a session to teach test driven development / design. It has been presented in various cities throughout North America. This is the final slides from the Agile 2013 conference in Nashville. Now includes all bricks you need to build your own kits.

Views

Total views

4,381

On Slideshare

0

From embeds

0

Number of embeds

443

Actions

Downloads

140

Shares

0

Comments

0

Likes

12

×