Search the web
Sign In
New User? Sign Up
extremeprogramming · Extreme Programming
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
jester shows bowling scoring could be simpler   Message List  
Reply | Forward Message #32277 of 152404 |
I really enjoyed reading "Engineer Notebook: An Extreme Programming
Episode" by Robert C. Martin and Robert S. Koss - it's a very
interesting article (available from
http://www.objectmentor.com/publications/xpepisode.htm)

Out of curiosity, I ran Jester (http://www.jesterinfo.co.uk) on the
code/tests from the paper, and it found something I thought really
interesting. Although the code looks fine, it can actually be
simplified quite easily.
Jester found:

D:\jester113\Game.java - changed source on line 16 (char index=249)
from if ( to if (false &&
CurrentFrame(int pins)
{
£if (firstThrowInFrame == true)
{
if (ad

i.e. there is an if statement where the tests still pass even when
only the false branch is ever executed. At first I found this
difficult to believe. Looking at the code I couldn't imagine how it
could be that the true branch is never needed. There were other
things reported by Jester too - I was beginning to wonder if Jester
was flawed.

On closer examination it turns out that all the code in the class
Game related to the instance variables "itsCurrentFrame"
and "firstThrowInFrame" can be removed and the tests still pass. The
method "score" simply needs to return "scoreForFrame(10)" - i.e. the
Game doesn't need to know what frame it's on, it can just ask the
Scorer for the score for frame 10 (the last frame) and the tests
still pass.

This is because the scores for any frames not yet thrown don't add
anything to the score - they are all 0 - so this gives the correct
answers at a minor cost of doing a few unnecessary additions (of 0).
(of course, Scorer could have a method something like
"totalScore" instead of calling "scoreForFrame(10)")

what do people think of this simplification of the code?

Ivan Moore

(simplified Game code below)

public class Game
{
public int score()
{
return scoreForFrame(10);
}
public void add(int pins)
{
itsScorer.addThrow(pins);
}
public int scoreForFrame(int theFrame)
{
return itsScorer.scoreForFrame(theFrame);
}
private Scorer itsScorer = new Scorer();
}




Mon Aug 20, 2001 8:45 pm

ivan_r_moore@...
Send Email Send Email

Forward
Message #32277 of 152404 |
Expand Messages Author Sort by Date

I really enjoyed reading "Engineer Notebook: An Extreme Programming Episode" by Robert C. Martin and Robert S. Koss - it's a very interesting article...
ivan_r_moore@...
Send Email
Aug 20, 2001
8:47 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help