tdd and refactoring with lego at agile2013
DESCRIPTION
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.TRANSCRIPT
![Page 1: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/1.jpg)
Understanding TDD and Refactoringwith LEGO
Bryan Beecham@BillyGarnet
Mike Bowler@mike_bowler
![Page 2: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/2.jpg)
Exercise - 1
Open up one LEGO packet
Build a person and a house out of LEGO
![Page 3: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/3.jpg)
Admire your work
Take a photo. Upload to Twitter. Brag to your friends.
![Page 4: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/4.jpg)
Reference
Test-DrivenDevelopmentBy ExampleKent Beck
![Page 5: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/5.jpg)
What is the goal of TDD?
It creates clean code that works ~ Ron Jefferies
![Page 6: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/6.jpg)
TDD
It is a predictable way to develop. You know when you are finished, without having to worry about a long bug trail.
![Page 7: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/7.jpg)
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.
![Page 8: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/8.jpg)
TDD
It improves the lives of the users of your software.
![Page 9: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/9.jpg)
TDD
It lets your teammates count on you, and you on them.
![Page 10: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/10.jpg)
TDD
It feels good to write it.
![Page 11: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/11.jpg)
The MantraRed - Green - Refactorphoto from doolwind.com
![Page 12: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/12.jpg)
The Mantra - Red
Write a small test that doesn’t work
![Page 13: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/13.jpg)
The Mantra - Green
Do the minimum to make the test work
![Page 14: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/14.jpg)
The Mantra - Refactor
Eliminate duplication
![Page 15: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/15.jpg)
Exercise - 2
Build a person and a house with TDD
![Page 16: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/16.jpg)
Prepare your environment
Clear the area in front of you. This is your program.
The perfect program!
![Page 17: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/17.jpg)
First Test
Does the person exist? No?
![Page 18: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/18.jpg)
Hurray!!!We failed the test! Celebrate! High 5s!
![Page 19: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/19.jpg)
Minimum to pass the test
Add a block. Can that be a person?
![Page 20: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/20.jpg)
Hurray!!!
The person now exists!
Not very impressive but it could represent a person.
We passed the test! We are rocking now!
![Page 21: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/21.jpg)
Refactor
Remove any duplication. In this case we’re good.
![Page 22: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/22.jpg)
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.
![Page 23: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/23.jpg)
We need a new test
The house is taller then the person.
Assert.IsTrue(house.height > person.height);
![Page 24: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/24.jpg)
Hurray!!! - More FailureThe person is the same size so we fail this test. Well done!
![Page 25: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/25.jpg)
Failure = Learning Opportunity
If your not failing, your not learning.
If your not learning...
![Page 26: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/26.jpg)
Minimum to pass the test
From the audience this time. Anyone? Bueller?
![Page 27: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/27.jpg)
Hurray!!! - Success
Alright, we passed the test.
![Page 28: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/28.jpg)
Refactor
Still very simple. Still nice and clean.
![Page 29: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/29.jpg)
Software Requirements
Software must do three things:
It must work
It must be understandable
It must be updatable
![Page 30: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/30.jpg)
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?
![Page 31: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/31.jpg)
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?
![Page 32: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/32.jpg)
Exercise - 3 Partners!
Break into groups of two for this next exercise.
When developers do this we call it Pair ProgrammingBerkley photo from the web
![Page 33: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/33.jpg)
New Requirements
Your new program needs to have:
A person
A house
A tree
An animal
A vehicle
![Page 34: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/34.jpg)
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?
![Page 35: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/35.jpg)
New Requirements
Your new program needs to have:
A person
A house
A tree
An animal
A vehicle
![Page 36: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/36.jpg)
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.
![Page 37: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/37.jpg)
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!
![Page 38: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/38.jpg)
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
![Page 39: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/39.jpg)
LEGO Refactoring
We will be using bricks with two points on top and panels with two points on top.
![Page 40: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/40.jpg)
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
![Page 41: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/41.jpg)
Your group of lego bricks represents a program.
Each one of these colour bands represents some logic in your code.
Class and Methods
![Page 42: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/42.jpg)
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!
![Page 43: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/43.jpg)
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.
![Page 44: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/44.jpg)
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.
![Page 45: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/45.jpg)
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.
![Page 46: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/46.jpg)
Audience Participation
Can anyone see other duplication?
![Page 47: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/47.jpg)
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)
![Page 48: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/48.jpg)
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.
![Page 49: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/49.jpg)
Super Fast BreakStand up and stretch - really, it’s important!Share something you’ve learned with a neighbour!
![Page 50: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/50.jpg)
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
![Page 51: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/51.jpg)
Decide on an idea
Shh...don’t tell the other tables.
(Jeopardy music...)
![Page 52: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/52.jpg)
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.
![Page 53: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/53.jpg)
Demo time!
A few teams will now present their creation.
Please share the tests that you came up with and point out the solution.
![Page 54: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/54.jpg)
Review
Test-Driven Development / Design
Refactoring
Pair Programming
A bit of developer speak
Experience working on a software team
![Page 55: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/55.jpg)
Questions?
Bryan Beecham@[email protected]
Mike Bowler@[email protected]
Please separate the lego bricks into their respective colours
![Page 56: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/56.jpg)
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.
![Page 57: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/57.jpg)
![Page 58: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/58.jpg)
![Page 59: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/59.jpg)
![Page 60: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/60.jpg)
![Page 61: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/61.jpg)
![Page 62: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/62.jpg)
![Page 63: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/63.jpg)
![Page 64: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/64.jpg)
![Page 65: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/65.jpg)
![Page 66: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/66.jpg)
![Page 67: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/67.jpg)
![Page 68: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/68.jpg)
![Page 69: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/69.jpg)
![Page 70: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/70.jpg)
![Page 71: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/71.jpg)
![Page 72: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/72.jpg)
![Page 73: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/73.jpg)
![Page 74: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/74.jpg)
![Page 75: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/75.jpg)
![Page 76: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/76.jpg)
![Page 77: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/77.jpg)
![Page 78: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/78.jpg)
![Page 79: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/79.jpg)
![Page 80: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/80.jpg)
![Page 81: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/81.jpg)
Success!
We have passed all tests! We can be confident that the bags contain the right pieces.
![Page 82: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/82.jpg)
No really, it’s over
![Page 83: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/83.jpg)
There are no more slides
![Page 84: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/84.jpg)
No trailers
![Page 85: TDD and Refactoring with LEGO at Agile2013](https://reader033.vdocuments.mx/reader033/viewer/2022061122/5470204baf795973118b480e/html5/thumbnails/85.jpg)
Looking for more?
Check out http://www.billygar.net
Links to HumanRefactoring, and soon more LEGO!