There should be room in programming for whimsy. This stuff is fun, and play is healthy. If somebody takes this thing seriously and copies the code into a production system, that's their own fault, not the author's.
Actually it's not less useful than the code the compilers you depend on use all the time. They really depend on such "bit twiddles." Guy Steele agrees too, read his foreword to the "Hacker's Delight," a whole book about such functions:
I would not use this code without being very thoughtful and intentional about where it was being used.
Sure, definitely not for everybody and every occasion. It's a platform dependent code. See my comment to cnvogel and look at his implementation for an example.
It's like if bridge designers didn't really know mechanics and just copy/pasted minecraft designs into the real world. Sure, it's not the fault of minecraft designers, but we can help kill fewer people by making better examples.
Either way, expecting People Who Know What They're Doing to shut up about it so that we can prevent People Who Don't Know What They're Doing from misunderstanding is shameful. The linked code wasn't published in a textbook, nor was it submitted as a Stack Overflow answer. You have no right to expect people to sanitize their writings just in case they see it.
Sorry if I sound prickly, but this sentiment makes my blood boil.
You're suggesting that something that doesn't happen (mechanical engineers + minecraft) is analogous to something that does happen (corporate programmers + code poetry).
Are you then suggesting that we outlaw minecraft because there may be a brain dead mechanical engineer alive?
What you're suggesting is akin to either outlawing essays like this or only allowing "Professional Engineers" (i.e. certification required) to write code?
The only solution is for the latter since the former is typical of a professional engineer seeking intellectual stimulation and should be applauded.
1. https://en.wikipedia.org/wiki/Argument_from_analogy#False_an...
"Professional Engineers" (i.e. certification required) to write code?
Do we let self taught basement dwellers design bridges crossed by millions of people and 100 story buildings?
Massive security branches? Massive fraud? Ineffective nationalized cybercommands?
Just because we can't see the world burning with our eyes doesn't mean lead in the air isn't giving us brain damage.
or like
https://graphics.stanford.edu/~seander/bithacks.html
By keeping the decimal constants he diminishes the chance to be attributed.
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/ ).
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.
> (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?
See cnvogel's attempt to measure it:
https://news.ycombinator.com/item?id=10513767
I also haven't accused anybody anything here.
Do you post similar rants to mechanical engineers building rube goldberg machines and electrical engineers building impractical extremely high voltage transformers?
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.
the last thing I did was changing the constants to decimal - they look way more scary this way ;>
because, you know, programming should be innately difficult and confusing so we can laugh at others who understand less than we do.
Never underestimate how many times code (any code) posted online will be copy/pasted throughout the world everywhere from school projects to production systems.