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.
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.
Continuing our series of ‘Same Kata, Different Languages,’ we have a very special performance in Python by Gary Bernhardt:
Gary Bernhardt is an independent software contractor in Seattle specializing in the dynamic languages Python and Ruby. A brutal minimalist, he is bent on the destruction of all existing software except Emacs and Vim, the two One True Editors.
Gary’s a [...]
Next in the series ’same Kata, different language’ I wanted to post my very own Kata in Scheme.
Currently I am learning Scheme. Due to my lack of knowledge in Scheme I could not write the tests (nor code) for the negative numbers part of the string calculator. I would have loved to get there, but [...]
Since the String Calculator kata was posed by Roy Osherove, I asked him to take a look at my solution and give me feedback. He was kind enough to write an insightful blog post with some comments. Since he took the time to write them, I thought it fair to weigh in with my responses.
Roy:
Partial [...]
Continuing our series of ’same kata, different languages,’ Giordano Scalzo provides us with a great view of the kata in Scala. I’ve fooled around a little bit with Scala, but definitely felt like I was just writing java in a not-quite-different environment. Watching Giordano code was very refreshing.
Giordano Scalzo is a Software “jack of all [...]
For our first in the series of ’same kata, multiple languages,’ we have a treat for everyone, Gabriele Lana is doing it in Erlang.
Gabriele Lana is a software journeyman living in Milan (Italy). Since 1998 he works as a developer and consultant. In 2000 he started using Agile practices in real time and embedded industries, proving their effectiveness [...]
For the next few weeks, we will be experimenting a bit by having guests doing the String Calculator kata in different languages. I did it originally in Ruby, and we have Erlang, Scala, Clojure and Python coming. I’ll be contacting Roy Osherove, who sparked this kata, to do it in C# for us.
Watching the same [...]
Due to time constraints, we won’t be having a katacast this week. It takes a long time to prepare one of these, and, unfortunately, the past couple weeks have seen some unfortunate things come up to take attention. As a result, developing, practicing and screencasting a new kata each week is undoable in the short [...]
Roy Osherove and Gil Zilberfeld of TypeMock talked about the katacast series on their podcast, ‘This Week in Testing,’ and called me out to do Roy’s standard TDD practice, String Calculator. There are a few screencasts of this kata in C# linked from his page, which are well-worth watching. It is always interesting seeing the [...]