jevansio Posted October 7, 2010 Share Posted October 7, 2010 The code looks like it's trying to turn an int (the percentage payout - I'm guessing intended to be between 72 and 98) into an enum. Becuase the enum is non-typed, the underlying implementation actually generates ints starting at 0 to represent the enumeration. The rewrite is taking advantage of this fact by implementing the conversion as a mathematical algorithm: (PercentagePoint - 72) divided by two, rounded down. (use of the bitshift is a fast way of doing divide by two, round down). To me - the bitwise shift is non-obvious, the ab(use) of the fact that the enum is actually an int is risky, and the edge/error cases (PercentagePoint98) are now handled differently, but the new implementation will be a lot quicker. It's a decision for absolute performance vs. defensive coding and maintainability, IMO Sorry I should have read your first post as it pretty much sums up my thoughts/feelings on the code snippet Quote Link to comment Share on other sites More sharing options...
BazzaAlpine Posted October 7, 2010 Share Posted October 7, 2010 looks like the sort of code I'd do but then I'm a QA'er not a programer. Quote Link to comment Share on other sites More sharing options...
Nodalmighty Posted October 7, 2010 Author Share Posted October 7, 2010 Percentage Payout can only be 72 to 98 percent. That is hard coded in the shell as it's HMRC law for AWP. I work in games, where code speed above and beyond is the order of the day. Engine management code requires the same level of optimisation. I know what assembler the complier will produce from the C code, that is why giving it a helping hand makes for better underlying machine code. The enum is only used within this function so changing it would not effect any other code. I don't know what's more worrying, That people found my 1 line of code difficult to read or the fact someone tried to justify 13 nested if else statements as good coding practice. Quote Link to comment Share on other sites More sharing options...
kjgreen3 Posted October 7, 2010 Share Posted October 7, 2010 10 Bad Programmer 20 Goto 10 Quote Link to comment Share on other sites More sharing options...
caseys Posted October 7, 2010 Share Posted October 7, 2010 http://www.pbm.com/~lindahl/mel.html Now that's programming. EDIT : Quote Link to comment Share on other sites More sharing options...
MrRalphMan Posted October 7, 2010 Share Posted October 7, 2010 I think I see what's wrong here, there are comments. Urrgh. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.