in discussion Coders Dojo / Coder's Dojo in Linköping » A new Kata is born!
After four sessions I'm still very fond of the roman calculator. Yesterday we continued the work where we started. The code was not even compilable after the last pair left it. But after 5 minutes we were up and running. And I must say it was the right decistion to continue on the code, and not to begin again as we have done several times before. Now we see some things to deal with coming up very soon in the calculator. But the best part of it is ofcourse all the discussions about TDD, BDD, and refactoring.
Yesterday we had a great discussion about
- why we need to refactor at all
- can we overdo refactoring?
- what is the next test after a refactoring that make the code more generalized?
- what happens to tests if we need to split a class
The third question was perhaps the insight-of-the-day.
After adding a test, then code just to make the test pass over and over again, we had some ugly if-statements with different cases that we wanted to refactor, generalizing just a little bit to remove all the chain of if statements, duplication, etc. The pair did it.
We got a green bar after the refactoring. Good - lets move on. But some protested when the pair wanted to go on with the next test to be able to add more functionality. What if there's something wrong with that refactoring? What if…? What assumptions have we made? Shouldn't we try to break it?
Everybody had the gut feeling that there might be some case we had left out…
The next tests proved that the gut feeling was there for a reason.
Insight:
Before a refactoring, ask your self - will I generalize the code? Do I need more tests before I get going with it?
After a refactoring, ask your self - have I generalized the code? Then the next tests should be in the same "theme" as the last tests and the code I just added.
The fifth question came during the break, and also in the talk after the Dojo. Some of the participants hoped that we would come longer in the Kata soon, so we would see class splitting and all that somes with that. Of course they had real world experience of the pain of moving tests and all the decisions you have to do there. Some said that it would be fun to do a much longer Dojo, to be able to come into these questions, and that's one reason why we at Responsive have developed the "Developer training course" where you have a full day of TDD and pair programming.