Successfully reported this slideshow.
Your SlideShare is downloading. ×

TDD and Refactoring with LEGO

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 59 Ad

More Related Content

Recently uploaded (20)

Advertisement

TDD and Refactoring with LEGO

  1. 1. Understanding TDD and Refactoring with LEGO Bryan Beecham @BillyGarnet 90 minutes
  2. 2. Introduction
  3. 3. Exercise - 1 Open up one LEGO packet Build a person and a house out of LEGO
  4. 4. Admire your work Take a photo. Upload to Twitter. Brag to your friends.
  5. 5. Reference Test-Driven Development By Example Kent Beck
  6. 6. TDD Clean code that works ~ Ron Jefferies
  7. 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. 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. 9. TDD It improves the lives of the users of your software.
  10. 10. TDD It lets your teammates count on you, and you on them.
  11. 11. TDD It feels good to write it.
  12. 12. The Mantra Red - Green - Refactor photo from doolwind.com
  13. 13. The Mantra - Red Write a small test that doesn’t work
  14. 14. The Mantra - Green Do the minimum to make the test work
  15. 15. The Mantra - Refactor Eliminate duplication
  16. 16. Exercise - 2 Build a person and a house with TDD
  17. 17. Prepare your environment Clear the area in front of you. This is your program.
  18. 18. First Test Does the person exist? No?
  19. 19. Hurray!!! We failed the test! Celebrate! High 5s!
  20. 20. Minimum to pass the test Add a block. Can that be a person?
  21. 21. Hurray!!! The person now exists! Not very impressive but it could represent a person. We passed the test! We are rocking now!
  22. 22. Refactor Remove any duplication. In this case we’re good.
  23. 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. 24. We need a new test The house is taller then the person. Assert.IsTrue(house.height > person.height);
  25. 25. Hurray!!! - More Failure The person is the same size so we fail this test. Well done!
  26. 26. Failure = Learning Opportunity If your not failing, your not learning.
  27. 27. Minimum to pass the test From the audience this time. Anyone? Bueller?
  28. 28. Hurray!!! - Success Alright, we passed the test.
  29. 29. Refactor Still very simple. Still nice and clean.
  30. 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. 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. 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. 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. 34. New Requirements Your new program needs to have: A person A house A tree An animal A vehicle
  35. 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. 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. 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. 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. 39. LEGO Refactoring We will be using big bricks with two points on top and panels with two points on top.
  40. 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. 41. Class and Methods Your group of lego bricks represents a class Each one of these colour bands represents a method
  42. 42. Duplication 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 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. 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? Important Note: Consider Light and Dark Green the same colour for this exercise. (that was a hint btw)
  47. 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. 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. 49. Break Stand up and stretch - really, it’s important
  50. 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. 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 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. 53. Demo time! Each team will now present their creation. Please share a few tests that you came up with.
  54. 54. Review Test-Driven Development / Design Refactoring Pair Programming A bit of developer speak
  55. 55. Questions? Bryan Beecham @BillyGarnet bryan@icebergideas.com
  56. 56. No really, it’s over
  57. 57. There are no more slides
  58. 58. No trailers
  59. 59. Looking for more? Check out http://www.humanrefactor.com Soon to have lot’s of cool info there

Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

×