## Re: [XP] Duplcation, Bad Code and Abuse...

Expand Messages
• ... This is removing the duplication from some context free code (which shares the same syntax as the bowling scoring example) to see where it goes. So far we
Message 1 of 106 , Oct 15, 2004
Ken Boucher wrote:
>
>>subTotal[3]
>>subTotal.runningTotal( r, c )
>>t = subTotal.findFirst( 10 ) + 1
>>s = t.inRange( 1, 2 )? subTotal[2] : subTotal[1]
>
> I'm just curious. Is this result of mercislessly refactoring the
> bowling game scoring code to make it better?

This is removing the duplication from some context free code (which
shares the same syntax as the bowling scoring example) to see where it
goes.

So far we have moved from this:

if ( r[c] == 10 )
s = r[c] + r[c+1] + r[c+2]
else if ( r[c] + r[c+1] == 10 )
s = r[c] + r[c+1] + r[c+2]
else
s = r[c] + r[c+1]

to something like:

subTotal[3]
subTotal.runningTotal( r, c )
t = subTotal.findFirst( 10 ) + 1
s = t.inRange( 1, 2 )? subTotal[2] : subTotal[1]

or perhaps:

subTotal[3]
subTotal.runningTotal( r, c )
s = subTotal[ subTotal.findFirst(10).inRange( 0, 2 )? 2 : 1 ]

It should still score bowling though.
• ... This is removing the duplication from some context free code (which shares the same syntax as the bowling scoring example) to see where it goes. So far we
Message 106 of 106 , Oct 15, 2004
Ken Boucher wrote:
>
>>subTotal[3]
>>subTotal.runningTotal( r, c )
>>t = subTotal.findFirst( 10 ) + 1
>>s = t.inRange( 1, 2 )? subTotal[2] : subTotal[1]
>
> I'm just curious. Is this result of mercislessly refactoring the
> bowling game scoring code to make it better?

This is removing the duplication from some context free code (which
shares the same syntax as the bowling scoring example) to see where it
goes.

So far we have moved from this:

if ( r[c] == 10 )
s = r[c] + r[c+1] + r[c+2]
else if ( r[c] + r[c+1] == 10 )
s = r[c] + r[c+1] + r[c+2]
else
s = r[c] + r[c+1]

to something like:

subTotal[3]
subTotal.runningTotal( r, c )
t = subTotal.findFirst( 10 ) + 1
s = t.inRange( 1, 2 )? subTotal[2] : subTotal[1]

or perhaps:

subTotal[3]
subTotal.runningTotal( r, c )
s = subTotal[ subTotal.findFirst(10).inRange( 0, 2 )? 2 : 1 ]

It should still score bowling though.
Your message has been successfully submitted and would be delivered to recipients shortly.