tag:blogger.com,1999:blog-9121642240025958832.post6033409312222078099..comments2024-03-28T04:18:45.370-07:00Comments on Trystan's blog: TDDing yourself into a cornerTrystanhttp://www.blogger.com/profile/15653418292042541807noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-9121642240025958832.post-50698124385644261532023-08-07T06:54:13.075-07:002023-08-07T06:54:13.075-07:00kars
silivri
yalova
bilecik
bitlis
Z2OPAA<a href="https://kars.escorthun.com/" title="kars" rel="nofollow">kars</a><br /><a href="https://silivri.escorthun.com/" title="silivri" rel="nofollow">silivri</a><br /><a href="https://yalova.escorthun.com/" title="yalova" rel="nofollow">yalova</a><br /><a href="https://bilecik.escorthun.com/" title="bilecik" rel="nofollow">bilecik</a><br /><a href="https://bitlis.escorthun.com/" title="bitlis" rel="nofollow">bitlis</a><br /><br />Z2OPAAburaknoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-47083480868359357132013-06-19T08:57:16.214-07:002013-06-19T08:57:16.214-07:00Good advice Danil. The subtle duplication is usual...Good advice Danil. The subtle duplication is usually the hardest for me to clean up. I do like the idea of inverting the lookups to make it more clear - I'll play around with that.Trystanhttps://www.blogger.com/profile/15653418292042541807noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-13848422535048428982013-06-19T07:46:17.922-07:002013-06-19T07:46:17.922-07:00I'm not sure what constraints the Transformati...I'm not sure what constraints the Transformations add to the problem, but looking at your current state, your "refectoring" steps would seem to have left quite a lot of duplication.<br /><br />I would probably start with a refactoring that re-orders your if statements... if (i == 0) return ""<br /><br /> if (i % 1000 == 0) return numeral(i-1000) + "M"<br /> if (i % 500 == 0) return numeral(i-500) + "D"<br /> if (i % 100 == 0) return numeral(i-100) + "C"<br /> if (i % 50 == 0) return numeral(i-50) + "L"<br /> if (i % 10 == 0) return numeral(i-10) + "X"<br /> if (i % 5 == 0) return numeral(i-5) + "V"<br /><br /><br /> if (i % 1000 <= 900) return numeral(i-900) + "CM"<br /> if (i % 100 <= 90) return numeral(i-90) + "XC"<br /> if (i % 10 == 9) return numeral(i-9) + "IX"<br /><br /> if (i % 500 <= 400) return numeral(i-400) + "CD"<br /> if (i % 50 <= 40) return numeral(i-40) + "XL"<br /> if (i % 5 == 4) return numeral(i-4) + "IV"<br /><br /> numeral(i-1) + "I"<br /><br />That first section is clearly<br /> if (i % x == 0) return numeral(i-x) + lookup(x)<br />over an enumerated set of x....<br /><br />The duplication here is a bit more subtle, because<br />your constants are spelled incorrectly<br /> if (i % 1000 <= 900) return numeral(i-900) + "CM"<br />becomes<br /> if (i % 1000 <= (1000-100)) return numeral(i-(1000-100)) + lookup(100) + lookup(1000)<br /><br />It might be that it makes sense to invert all of the lookups<br /> if (i % lookup(M) <= (lookup(M)-lookup(C))) return numeral(i-(lookup(M)-lookup(C))) + "MC"<br /><br />In either case, there's a meaningful name refactoring<br />to apply to lookup().<br /><br /><br /><br />Danilnoreply@blogger.com