Am I the only one who thinks the “correct” code is awful? I’d much rather just see an if statement added to the first padding code. Bit twiddling should be reserved for inner-inner-inner-loop optimisations. They’re all about “how” with none of the “why”
Am I the only one who thinks the “correct” code is awful? I’d much rather just see an if statement added to the first padding code. Bit twiddling should be reserved for inner-inner-inner-loop optimisations. They’re all about “how” with none of the “why”
Yeah, I looked at the “fixed” code and am like, “oh man, I have to get out a REPL an start seeing how this works”
or this
I came up with your second solution too :)
return ((size / 2048) + (((size % 2048) != 0) ? 1 : 0)) * 2048;i’m guessing once you’ve done enough bit twiddling, that just reads as a mod operation to you
Unit testing. I know, this was the 90’s, unit testing didn’t exist yet. I’m sure everyone would write a unit test for this nowadays. Right?