Calvin And Hobbes Discuss Tdd

A compilation of conversations on the TDD Group. Hope it helps you discuss TestDrivenDevelopment. MattScilipoti

Calvin: "I don't do test driven programming. I write some code, and test it manually, walking through it in the debugger, checking that it works."

Hobbes: "How do you know that it works? Could you express that as a test before you run your code?"

Calvin: "I can't think about the test until I've thought about the code."

Hobbes: "Changing the habit of writing code before the test can be a bother. Try this: Write the code on paper. Then write a test."

Calvin: "Paper?!"

Hobbes: "What if you just outlined the code on a whiteboard and didn't write any real code? Could you still write a test first?"

Calvin: "I'd feel silly doing that alone."

Hobbes: "What if you explained it to your pair partner? Could you still write a test first, or maybe have your pair partner write the test?"

Calvin: "That could work."

Hobbes: "I notice you're refactoring without tests. What's that like?"

Calvin: "After I refactor, I have to test it again manually, in case I make a mistake doing the refactoring."

Hobbes: "Wouldn't it be easier to run some quick tests before and after you you refactor?"

Calvin: "Well duh! If I had the tests."

Hobbes: "If you do test-driven development, your tests drive the design of your code, and as a side-benefit, you get a nice small set of regression tests that make refactoring safe."

Calvin: "Perhaps if I start by thinking about the interfaces that my class or module would need to support, I would be able to write the unit test first? Does this sound like the kind of thing I should be trying more of?"

Hobbes: "I think so. If I were given just the task of writing a class or module, my first test would describe a very simple case of what I wanted from that code. The interface of this not-yet-written code is evolving, of course, during my test-driven development process. Since I'm calling the functions that I need at each moment, without a care how (or if) they are implemented, it tends to create a pretty usable interface."

Calvin: "So you find out quickly if your interface functions are no good when you're forced to use them as client, in the tests, before investing a lot of work at writing them!"

Hobbes: "Now you're getting it."

Calvin: "Tell me, when you think of a feature, is your next thought about testing or implementation?"

Hobbes: "I just think about using that feature. Which leads me to an example of how I would use it. Now I just write down the results I expect from that, and voila, there's the test. I'm not even actively thinking "I have to write a test now. How can I test it?". My main focus is how I can use it."

-- C. KeithRay


This is very interesting, and well-written, but I doubt Calvin would ever be that rational.

Hobbes: Have you written tests for that code yet?

Calvin: Tests?! TESTS?! I don't need tests! What do I need tests for? Don't you think I can write something this simple without using tests as a crutch?! I know it's right!

Hobbes (rolling his eyes): Of course you do.

Calvin: Right. Now help me fix these last four bugs.

-- JbRainsberger


>>Calvin: Right. Now help me fix these last four bugs.

Hobbes: I thought I was doing that.

-- LaurentBossavit

Calvin: Voila! I just added the supertransmogrifier feature, now for the...

Hobbes: You know you should refactor this code. It smells.

Calvin: It WHAT?!

Hobbes: This code wants to be refactored. You just duplicated this here, here and here.

Calvin: So WHAT?

Hobbes: What if the call to the supertransmogrifier should be changed one day for some reason?

Calvin: You mean I should stop everything I'm doing right now and start thinking of something that could happen one day for some hypothetic reason?

Hobbes: You said 'be prepared' was your motto, remember?

Calvin: Who gives a damn about what could happen some day? What makes you think I should lose myself in conjecture or aesthetics when there's all that code to be finished before Mom calls us for dinner?

Hobbes: Well, if a change or an error happened you'd have to do ShotGunSurgery all over.

Calvin: Shotgun surgery! COOL! Where could I paste this again?

Hobbes: Why not into that small dustbin?

Tip..Tip, tip. Click

Calvin: This darn code is longer than ever, and it still won't run properly.

Hobbes: Yeah. But now we precisely KNOW that ONE of the defects lies SOMEWHERE in those 25000 lines.

Mom: CALVIN! Dinner's ready!

Calvin: HEY! My program isn't just half finished! Where did all the time go?

Hobbes: I can tell but there's no more time for conjectures.

Mom: CALVIIIN!

Calvin: C'mon Hobbes; help me assemble those last blocks. Then, we'll clean it up later at night!

Hobbes: Ah? Then we don't sleep after that?

Calvin: Are you lazy or what?


Calvin: This meeting of the Get Rid Of Slimy Sourcecode ESpecially Tests club will now come to order! SeniorSoftwareEngineer Hobbes will read the minutes of our last StandupMeeting!

Hobbes: Thank you. 9:30 - Meeting called to order. ChiefArchitect-For-Life Calvin proposes resolution condemning existence of tests. 9:35 - SeniorSoftwareEngineer Hobbes abstains from vote. 9:36 - MethodologicalPurity of SeniorSoftwareEngineer called into doubt. 9:37 - ExtremeScheduleNegotiation. 10:15 SlowDownToSpeedUp. ChiefArchitect rebuked for ParkingLotTherapy.

Calvin: Is this a great club or what?

Hobbes: 10:16 - TheyreJustRules. New estimates for all stories.

[...]

Calvin: All right, here's the plan! We make up detailed AcceptanceTests for low priority UserStory(s) and make sure the customer reviews them. Naturally the system fails the tests and the customer puts all priority on fixing them! Then when the system is delivered management blames the customer and demands an end to all Tdd!

Hobbes: Why don't we just skip writing stories in the first place?

Calvin: You're a good hacker, Hobbes, but let's face it, you don't grok the ManagementCycle.

Hobbes: I still think my idea sort of makes sense ...

[...]

Calvin: It's a dark day for the Get Rid Of Slimy Sourcecode ESpecially Tests club. Our great plan backfired and I'm the one who got blamed! <Sigh>

Hobbes: If you resign can I be ChiefArchitect?

Calvin: I DIDN'T SAY I WAS RESIGNING!

[...]

Calvin: Well Hobbes, the release may have been scrubbed but the project goes on! As a SystemMetaphor we'll do BigDesignUpFront! The spirit of GROSSEST cannot be extinguished! And to assure XpCourageValue I award our UserStories new estimates.

Hobbes: Yayy! A good StandupMeeting always ends with us making new estimates!

Calvin: This is such a great club!

[...]

Management: Here Calvin, I increased the project budget for you and Hobbes.

Calvin: Gee thanks, Management. <to Hobbes> What do you say we write an OpenSource project while we spike our BigDesignUpFront?

Hobbes: Oh boy!

Calvin: It's looking like a good year ol' buddy.

Hobbes: I love AgileDevelopment.

(With apologies to Watterson. And Beck. ~Pete)


EditText of this page (last edited May 6, 2009) or FindPage with title or text search