tag:blogger.com,1999:blog-2360295419257510421.post1412643762744972392..comments2012-06-27T19:01:47.842+02:00Comments on CoderNub: C# Bowling Kata as a TDD Exercise (Revisited)Anonymoushttp://www.blogger.com/profile/15625546905018255907noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2360295419257510421.post-49297022318030763792010-01-09T08:40:23.464+01:002010-01-09T08:40:23.464+01:00Sorry, currentRoll wasn't a class member I thi...Sorry, currentRoll wasn't a class member I think. That line wasn't supposed to be there. I was just getting confused between different versions of the code. :)Anonymoushttps://www.blogger.com/profile/15625546905018255907noreply@blogger.comtag:blogger.com,1999:blog-2360295419257510421.post-62502749006230700402010-01-09T06:14:25.895+01:002010-01-09T06:14:25.895+01:00Thanks for the comment. currentRoll was already a ...Thanks for the comment. currentRoll was already a class member. As commented above, pasting in the unrefactored code was actually my mistake, which I didn't notice until I was away from the machine that had the code on it. I've edited with the refactored end result now.<br /><br />How would using an array solve the gutterballs failure? The error was happening from trying to access invalid indexes, which would be a problem with an array as well. Though you're right in that an array would suit just fine here as well. I do like the dynamicity of a list type though, since you're not bowling 21 balls every time. <br /><br />On the other hand, I guess a maximum of nine unused memory blocks isn't the worst of overhead out there, and I might lose more than that by using a full list object rather than a simple array. ;)Anonymoushttps://www.blogger.com/profile/15625546905018255907noreply@blogger.comtag:blogger.com,1999:blog-2360295419257510421.post-5959909941738028412010-01-09T05:49:45.894+01:002010-01-09T05:49:45.894+01:00Excellent work! This is much improved over your pr...Excellent work! This is much improved over your previous attempt (which was quite good as well).<br /><br />As far as the "superfluous" tests are concerned, I think they are fine. While there are tests that probably don't need to be there I feel more confident with them there. Keeping them does come at a cost, and it is good to consider the cost while making a decision.<br /><br />There are some excellent refactorings that could be done in the Scorer class, and when I teach TDD it includes a refactoring step: Test -> Code -> Refactor.<br /><br />Specifically, a few helper methods could vastly improve the expressiveness of the code. For instance:<br /><br />if (rolls[currentRoll] == 10)<br /><br />could be replaced by <br /><br />if (isAStrike(currentRoll)<br /><br />isAStrike would be a simple method, but there is no extra overhead and the conditional becomes very obvious.<br /><br />Likewise, scoring a strike or spare could be encapsulated in a helper method to improve expressiveness:<br /><br />score += (scoreASpare(currentRoll)<br /><br />Finally, your frames loop: why not make it a bit more expressive:<br /><br />for (var frame = 0; frame < 10; frame++)<br /><br />Oh, and next time you might try just using an int array (int[21] to be exact) for rolls and make currentRoll a class member: this solves the problem of forcing a complete game before we can score the game (the all gutterballs failure).<br /><br />Very well done! I'm enjoying your blog entries. Keep 'em coming! :)Paulhttp://salientblue.comnoreply@blogger.com