After being away for a couple weeks due to conferences and sickness, we present another entry in our “Same Kata, Different Languages” series: the String Calculator in Groovy by Itay Maman. This will most likely be the last of the String Calculator katas for a while, as we’ve been doing them for a long time now; time for something different next week.
After being away for a couple weeks due to conferences and sickness, we present another entry in our “Same Kata, Different Languages” series: the String Calculator in Groovy by Itay Maman. This will most likely be the last of the String Calculator katas for a while, as we’ve been doing them for a long time now; time for something different next week.
Itay Maman is a hopeless programmer living in Haifa (Israel). His doing a Ph.D. was just an excuse for writing cool software and for being able to read and hack cool code that others have written (Compilers and such).
Groovy is an interesting language, since it looks so remarkable similar to Java, but definitely has less of the syntax. Here’s Itay’s description of doing the kata:
I repeatedly practiced this Kata over the last few weeks. I eventually got to the point where I felt I’m doing it on “Auto pilot”. The Kata that I recorded was a bit different – I decided to take steps that are slightly than my usual, which made the whole thing interesting as I had to improvise here and there.
The nice thing about this Kata is its diversity. In “TDD By Example” Kent Beck lists three basic “moves”: (1) Fake it till you make it; (2) Triangulation; and (3) Obvious implementation. All three moves can be found here.
“Fake it” is my default. This quickly gets me to Green thereby providing the opportunity to refactor even before the implementation is complete. I like to think about it as a preemptive refactoring. You can see it in the last test. At 10:10 I inject a fake implementation. Then I do a preemptive refactoring: I introduce the “negs” variable which is the vehicle on which the real implementation is built.
Triangulation. 4:57 minutes into the Kata I am in a position where I reworked a “Fake it” implementation into a more general form, but I am not done. There is still a hard coded assignment: “delimiter = ‘;’”. At that point I felt that I covered enough grounds in the application code so I go back to the unit test and introduce a fresh test that fails (5:07). This leaves me with no option but to generalize the assignment into “delimiter = s.charAt(2).toString()”
Obvious implementation. There are three tests where the solution is just a few keystrokes away so I directly code it in. For example, when the shouldAllowNewlines() tests yields Red (3:38) I move to the application code, add a “|\\n” to the regular expression and get back to Green in 6 seconds.
I like his description of some different techniques with TDD. I really enjoyed this katacast, as it is a pretty nice, fluid example of what you can do when you’ve practiced.
If you’d like to contact Itay:
Twitter: http://www.twitter.com/pembleton
As always, feel free to comment. Constructive comments are always welcome! If you are inspired to do your own kata and would like to prepare something for katacasts, definitely contact me.
StringCalculator Groovy from Itay Maman on Vimeo.
Is there a RSS feed for the videos only???