Channels ▼

Bil Lewis

Dr. Dobb's Bloggers

TDD is Great for University

February 15, 2011

I have not been a situation where I felt I could use TDD in my own development work, but when teaching classes, it has been fantastic.

So much of my own work consists of coming up with new and different ways of handling problems that haven't really been addressed before.

The direct consequence of this is that I throw away or radically revise most of my code fairly quickly. In trying to retain even simple regression tests, I have often put ridiculous amounts of effort into revising tests to match my new code, only to throw it away a week later when I decide on an alternative representation.

In the classroom, however, TDD is the best thing ever.

I am not impressed with our (i.e., any I've seen) current teaching curriculum and techniques. In teaching C++ as the introductory language, the texts I've used are pretty 1970s (IMHO). The typical assignment is "Write a program to print 'Hello World'" or some such. This puts the student right up against the C++ compiler from day one and many of them don't make it past day two.

What I did in those cases was to build a simple test harness with a set of tests that would run against the initial non-functioning code, obviously failing all tests. The students would then go in and modify the initial code to make it work. This meant that they never had to worry about starting from scratch, never had to wonder if they had linked the correct library, and if they ran into that completely baffling compiler error message, they could always just back up to a previous working version.

It also made verifying the programs simple — the students would give me a printout showing the tests all passing and the code online, which I would then scan, looking for programming issues. (I can read a program really fast.) So in class I would pop up snippets of students' code and talk about the techniques used.

The students loved it. A few have contacted me in later years, praising the approach.

So, yes. TDD rocks!

— Bil

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.