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[0]) 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 substring()
.
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…
5 replies on “Coding Dojo 9”
Any chance of making that cheat sheet available?
Jane, it’s over here.
Damn, that sounds like a great idea.
It’s a long way from Newcastle to Brighton, but, let’s say a chap was thinking of coming down, taking part and then returning to the frozen north with the intent of starting a Tyneside Coding Dojo. Would this hypothetical chap find a hypothetical sofa on which to lay his weary head? Hypothetically.
Piers, you’re more than welcome! Drop me an email to confirm. I think that the next dates are on upcoming.org…
Well, I’ve signed up for next Monday’s Dojo. Before I realised that it’s going to be in Java and I have to code. And my java knowledge is pretty much ‘read only, through my fingers and keeping a barf bag to hand’.
I tried emailing you, but I might have the wrong email address.