Jeremiah Flaga My thoughts and experiences on programming, life, atbp.

TDD might help in teaching about design, even without a teacher

Category:

In his talk, “The Deep Synergy Between Testability and Good Design (NDC 2010)”, Michael Feathers said these:

“If your code is not testable, then it is not a good design.”

“In general, every time you encounter a testability problem, there is an underlying design problem.”

“If you’re finding trouble testing things, reconsider your design and end up with something better.”

Perhaps writing tests can be used in teaching design when no teacher is available to teach design!?

We can just tell the student, “If it is hard to test, the design must be wrong. Try to find another solution.”

If you don’t know why good design matters… Good design will lead to less bugs, which means happy customers; and less time fixing bugs, which means happy programmers! Yehey!

And… Do we have a better way of writing testable code than writing the tests first? — TFD! I mean, TDD!

Writing the tests first surely will help us write testable code… And testable code is a very good indication of good design, as what Michael Feather said.

We can thus tell the student this instead: “Write your tests first before writing your production code. This process will help you write testable production code. And testable code is a very good indication of well designed code.”

Tests are tools

“… [TDD] practitioners discovered that writing tests first made a significant improvement to the design process.” — Martin Fowler

We should remember that the tests are just tools. They are just a means to an end. They are tools to help us when designing software (just as software are just tools in helping make the lives of people better [I hope], or easier at least).

We should not write tests just for the sake of writing tests; just so we have something to brag about — “See! I’m writing tests!!!”.

We should not write tests just because we are required to write tests. No! That would be boring! :grinning:

If we do not have the right reasons for writing tests, we should not be writing them at all. They will just be a waste of time.

Oh no!… I have to take that back. We have to write tests… but we should try to understand the reasons for doing so. We should not be writing tests blindly.

Testability does not imply good design

Also, Michael Feathers said that being testable does not imply good design, but well designed systems are testable. There is a direction to this synergy between testability and good design, he said.

Well designed? It must be testable!

Testable? It might be well designed!

Okay… back to my main point…

Student: “Where are you going?”

Teacher: “I’m going to fight a war… I don’t have so much time to spend with you… Just remember that if it is hard to test, the design must be wrong. And writing your tests first will help you write testable code… and testability is a very good indication of good design.”

Student: “Does that mean that I have to first learn about what good design looks like?”


← Previous | Archive | Next →

Comments