I’m just back from Dojo#9. We attempted Kata 4 again, but in Ruby this time. Even though I was the only one with much Ruby experience behind me, it still wasn’t much of a problem in practise. I did some cheat sheets, but they didn’t seem to be used much.
Exactly the same as the last time, we only completed the first part of the kata. I started the session by writing a small amount of code. In a very non-object oriented fashion. However, I honestly believe that for this problem an OO solution was utter overkill. The testing was probably useful, but to be quite frank a program this short can be visually inspected so easily, I hardly feel it’s worth it. Heresy, I know.
This is what I was aiming towards.
day = nil min_spread = nil File.foreach(ARGV) do |line| if line =~ /^s*(d+)s+(d+)s+(d+)/ spread = $2.to_i - $3.to_i if !min_spread || spread < min_spread min_spread = spread day = $1 end end end puts day
I’m pleased about using regexes though. They make the problem simpler (and more robust) than the previous Java solution using
Now, when it came to refactoring the program to get to the third part of the kata, an OO solution would have been more appropriate. Because you need to carry some state around, and you can obviously use inheritance to model the differences. And by that point, you’ve got two working programs you can extract a sensible design from.
Ah well. An entertaining evening. Big thanks to Joh for organising and FP for hosting. Sorry for disturbing the late workers…