5 ms·
This code was already difficult and confusing and the author obviously pokes fun at his own code by decimalizing the constants. No need to accuse him of elitist
by Confusion 11y ago
This code was already difficult and confusing and the author obviously pokes fun at his own code by decimalizing the constants. No need to accuse him of elitist or immoral behaviour.
- acqq 11y agoIt's a good and common practice to keep the constants in the sanest form and not obfuscate them, see the collections of such functions, like the already quoted http://aggregate.org/MAGIC/ http://aggregate.org/MAGIC/ or like https://graphics.stanford.edu/~seander/bithacks.html https://graphics.stanford.edu/~seander/bithacks.html By keeping the decimal constants he diminishes the chance to be attributed.
- stavrianos 11y agoSure, sure, in most contexts code as communication medium is laudable. Here, the game is to make people accustomed to understanding go "the hell just happened?" when it works. I like it.
- _yy 11y agoYeah but that does not apply to jokes.
- acqq 11y agoYou mean the whole article is a joke just because the article ends with "the last thing I did was changing the constants to decimal - they look way more scary this way"? I see it as a presentation of an efficient specialized function, just like the other bit hacks are (some already linked, one more, a whole book, here: http://www.hackersdelight.org/ http://www.hackersdelight.org/ ). If it's is to impress the uninitiated, such are more probable to not know the hex codes too. For them is the decimal number the one less scary than the hex one. For others, converting back to hex is just a tiny annoyance, nothing more.
- pavel_lishin 11y agoBut it's not efficient. The author even explicitly says so at the beginning: > (Disclaimer: It's not faster. It's not better. It's not production-quality code. It's just is and it was fun to make ;>) It's a joke, a joke with some context, that you tell other people who know the context. Would you accuse people of intentionally obfuscating things when they riff on "the door is ajar" joke?
- acqq 11y agoNo, on modern 64-bit processors it's definitely more efficient and faster than the loop variant. It's measurable. The author's disclaimer that it isn't faster is actually valid only for old or small processors. See cnvogel's attempt to measure it: https://news.ycombinator.com/item?id=10513767 https://news.ycombinator.com/item?id=10513767 I also haven't accused anybody anything here.
- deelowe 11y agoYou just won't give up will you? Do you post similar rants to mechanical engineers building rube goldberg machines and electrical engineers building impractical extremely high voltage transformers?
- acqq 11y agoCan you imagine that there are people who actually program on such a low level that they actually care about that kind of functions, constants and the number of T states that the resulting assembly code takes? I'm one of those. If these aspects aren't relevant to you please allow me to address them. The article author actually engineered an effective function for spreading out bits to bytes. I invite you to read the comments here that are actually mine and what's in them.