TDD and Refactoring with LEGO
Upcoming SlideShare
Loading in...5
×
 

TDD and Refactoring with LEGO

on

  • 2,782 views

 

Statistics

Views

Total Views
2,782
Views on SlideShare
2,757
Embed Views
25

Actions

Likes
7
Downloads
81
Comments
0

2 Embeds 25

https://twitter.com 24
https://si0.twimg.com 1

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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

TDD and Refactoring with LEGO TDD and Refactoring with LEGO Presentation Transcript

  • UnderstandingTDD and Refactoringwith LEGOBryan Beecham@BillyGarnet90 minutes
  • Introduction
  • Exercise - 1 Open up one LEGO packet Build a person and a house out of LEGO
  • Admire your workTake a photo. Upload to Twitter. Brag to your friends.
  • ReferenceTest-DrivenDevelopmentBy ExampleKent Beck
  • TDDClean code that works ~ Ron Jefferies
  • TDDIt is a predictable way to develop. You know when youare finished, without having to worry about a long bugtrail
  • TDDIt gives you a chance to learn all of the lessons that thecode has to teach you. If you only slap together the firstthing you think of, then you never have time to think ofa second, better thing.
  • TDDIt improves the lives of the users of your software.
  • TDDIt lets your teammates count on you, and you on them.
  • TDDIt feels good to write it.
  • The MantraRed - Green - Refactorphoto from doolwind.com
  • The Mantra - RedWrite a small test that doesn’t work
  • The Mantra - GreenDo the minimum to make the test work
  • The Mantra - RefactorEliminate duplication
  • Exercise - 2 Build a person and a house with TDD
  • Prepare your environmentClear 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 testAdd 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!
  • RefactorRemove any duplication. In this case we’re good.
  • Same thing for houseBlah, blah, awesome recreation by speaker...everyoneis extremely impressed and are thinking this might bethe best session of the whole conference.
  • We need a new testThe house is taller then the person.Assert.IsTrue(house.height > person.height);
  • Hurray!!! -More FailureThe person is thesame size so we failthis test.Well done!
  • Failure =Learning OpportunityIf your not failing, your not learning.
  • Minimum to pass the testFrom the audience this time. Anyone? Bueller?
  • Hurray!!! - Success Alright, we passed the test.
  • RefactorStill very simple. Still nice and clean.
  • Software RequirementsSoftware must do three things: It must work It must be understandable It must be updatable (Robert C. Martin...I think)
  • We need a new testIs the house wider then the person? No?We failed another test! Awesome! We are learning a lotabout improvements that are needed to our code.Let’s do the minimum to pass the test.Any duplication to remove?
  • We need a new testCan your person fit in the house? Yikes! No.We failed another test! Awesome! We are learning somuch 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 RequirementsYour 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?
  • ReviewLet’s take a few minutes to walk around and look ateverybody’s creations!Taking breaks and stretching your muscles is veryimportant to stay healthy
  • ApologyYou may have to break your wonderful new structuresfor the components for the next section.Don’t worry, there is more building to come!Please do take a photo. Remember @BillyGarnet if yourtweeting about the amazing time your having!
  • RefactoringRefactoring is the process of changing a softwaresystem in such a way that it does not alter the externalbehavior of the code yet improves its internal structure.~Martin Fowler
  • LEGO RefactoringWe will be using bigbricks with two pointson top and panels withtwo points on top.
  • Build our programStack up big (normal height) bricks like this:brown-red-blue-blue-red-green-yellow-red-greenbrown on top and green at the very bottom
  • Class and MethodsYour group of lego bricks represents a classEach 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 MethodWe are going to start by extracting the method. We willreplace the first big red block with a small red panel.Put the structure back together and put the big redblock on the bottom.This small red panel simply tells the program to go torun the big red block code.
  • Remove DuplicationNow let’s replace the other big red blocks with the flatred panels.We don’t need to move these big red blocks to thebottom 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 toread 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.
  • BreakStand up and stretch - really, it’s important
  • Exercise 4 -Team BuildArrange 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 ideaShh...don’t tell the other tables.(Jeopardy music...)
  • Break it into componentsTake a minute to write out each of the components thatneed to be built.Each pair will have a few minutes to build their partthrough TDD.We will then add the sections to the big project. Makesure 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.
  • ReviewTest-Driven Development / DesignRefactoringPair ProgrammingA bit of developer speak
  • Questions?Bryan Beecham@BillyGarnetbryan@icebergideas.com
  • No really, it’s over
  • There are no more slides
  • No trailers
  • Looking for more?Check out http://www.humanrefactor.comSoon to have lot’s of cool info there