Drawing: Tim Ottinger
Photo: Libby Ottinger
Cleanup: Jeff L.
We show flash cards to students in order to help them completely ingrain a concept, to the point where they don't think about something, they just know it. The classic flash card presents a student with a vocabulary word or a math expression for which we expect almost immediate recognition and response. I show you the Spanish vocabulary word "acuario" and you blurt out "fish tank!"
So, red-green-refactor. By definition, TDD says write the tests first. They should fail, since you've not built the functionality that the tests specify, and a GUI test tool will show red at this point. That's useful feedback that tells you to write just enough code to get all existing tests to pass; the GUI test tool shows us green. Finally, you can ensure that the code has an optimal design during a refactoring step, since you have tests to give you the confidence to change things. Spend a few minutes, improve the design, and re-run your tests, which should all still be green. The entire cycle should take about 5 minutes on average, and no more than 10 minutes.
If you've been doing TDD for more than a few days--I mean really doing it and not writing code first and then sneaking in a few tests afterward and then telling people "I got muh TDD's done"--this cycle should be starting to sink in. Those of us who've done TDD a little longer--maybe a few months--don't think twice about it. Red-green-refactor feels like the natural way for us to build software.
- Red - A common mistake for newbies to TDD is to gloss over the need to see the test fail first. It's part of keeping on course; the red is extremely valuable feedback that tells us our assumptions still hold true. Once in a while, they won't, and you'll have saved yourself a lot of time by finding that out immediately.
- Green - Keep rough track of how long it takes you to derive a solution that passes all your tests. If you're taking 5-10 minutes on average, or more, start figuring out ways to take smaller steps.
- Refactor - You should always take advantage of the refactoring step. Even if you added perfect code (that doesn't duplicate any other code in the system), treat the refactoring step as "mandatory bonus time." Poke around the area you're changing. Get rid of a warning. Rename a test. Improve the readability of an existing method. Follow the boy scout rule: Make things a little better when you leave than they were when you arrived. Note that the refactor step doesn't necessarily represent a single green test run: You should look to decompose refactoring efforts into even tinier steps, getting a rapid succession of green bars before moving on.
The other real advantage of having red first is that it shows your test configuration is right. If you've not named your test or test file correctly, or left off some attribute, then the test may not be running at all.
ReplyDeleteSometimes a programmer thinks he's got a green bar when in fact the test was never run. That's also why my first test is usually assert(False) or the like. Test-after programmers make this mistake all the time and don't even know it.
this is amazing stuff,
ReplyDeleteis there one place where I can find all of the flashcards?
I want to print a whole bunch of them, and brand them with my clients logo...
This is the place you can find them right now. We're looking to publish the whole set as a deck of cards, and a book with one mini-chapter per card.
ReplyDeleteOf course the cards have our copyright, and we need to have a talk about branding, ownership, and attribution. But we're pleasant people (well, Jeff is, and I like to think I am) and I'm sure we can work out details with you.
I want a t-shirt with this drawing on it. Seriously.
ReplyDeleteDo not live in make it difficult. live life for what it is then surely life will be wonderful.
ReplyDeletemaintain the security of yourself is very possible from current threats.
ReplyDeletela technologie d'aujourd'hui rend la vie plus facile à passer. Toutes les activités peuvent être réalisées en toute simplicité grâce à la dernière technologie
ReplyDeletetoday's technology makes life easier to be passed. all activities can be done with ease thanks to the latest technology
ReplyDeleteAmazing...!!!
ReplyDeleteWhats wrong.?
ReplyDeleteI am fascinated by this post. Thank you very much. Waralaba And it is true.
ReplyDeleteIf you've not named your test or test file correctly, or left off some attribute, then the test may not be running at all.
ReplyDeleteI think this is a real great article post.Really looking forward to read more. Want more.
ReplyDeleteHarga Samsung Galaxy
Makasih atas infonya... sangat bermanfaat...
ReplyDeleteMebel Minimalis
Mebel Jepara
Mebel Jati
Mebel Murah
Toko Mebel
Mebel Jepara Murah
Wao...
ReplyDeleteNice Info
Thanks for information...
ReplyDeleteThanks Brother. . .
ReplyDeleteGood Job Bro...
ReplyDeleteThanks Informasinya...
ReplyDeleteGood Nice site
ReplyDeleteModel Atap Rumah Minimalis
Desain Rumah Minimalis Modern 2 Lantai
Rumah Idaman Minimalis
Gambar Rumah Minimalis Sederhana
Desain Rumah Minimalis Modern
Desain Rumah Minimalis 2 Lantai Type 45
Desain Rumah Minimalis 1 Lantai
Rumah Minimalis Sederhana Type 36
Desain Rumah Minimalis 2 Lantai
Gambar Rumah Minimalis
Desain Rumah Miniamlis Type 54
Desain Rumah Sederhana
Desain Rumah Minimalis Type 45
Wow, that's amazing post. I Like it so much . Thankyou For Share :)
ReplyDeleteIt's true factor :) Thank's for info . I Feel so greatfull by visiting you're site..
ReplyDeleteThis is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.
ReplyDeleteHarga Lenovo S920
Nice sharing for me. Please, keep posting :)
ReplyDeleteAwesome post and useful for everyone. Thank you!
ReplyDeleteHello
ReplyDeleteAwesome post
Segala Jenis Android
I can see that you are putting a lots of efforts into your blog. Keep posting the good work.Some really helpful information in there. Bookmarked. Nice to see your site. Thanks!
ReplyDeleteHarga Canon EOS 600D
I think your post is very nice and useful for everybody. Thank you.
ReplyDeletethat's good looking, very nice and usefull ... thank's
ReplyDeleteThank you for another essential article. Where else could anyone get that kind of information in such a complete way of writing? I have a presentation incoming week, and I am on the lookout for such information.
ReplyDeleteI'm waiting your new post. yeahaaa
ReplyDeleteCause this blog so nice..
thank you, the information very helful
ReplyDeleteThank you for your information.. Keep sharing
ReplyDeletenice site btw
ReplyDeleteMajas Pleonasme
Medionize