4 ms·
The whole thing is whimsy. You'd never want to use this approach at all in a production system. Using decimal constants instead of hex is the least of the sins
by mikeash 11y ago
The whole thing is whimsy. You'd never want to use this approach at all in a production system. Using decimal constants instead of hex is the least of the sins here.
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.
- acqq 11y ago> You'd never want to use this approach at all in a production system 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: http://www.hackersdelight.org/foreword.pdf http://www.hackersdelight.org/foreword.pdf
- Splines 11y agoThe difference being that the compiler knows what sort of bit-twiddling it should be doing and what sort of bit-twiddling it should not be doing. I would not use this code without being very thoughtful and intentional about where it was being used.
- acqq 11y ago> 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.
- seiji 11y agoMy job is basically fixing the code and processes of corporate programmers who copy/paste examples from websites into production systems. There's little understanding of how the code works and almost no reading of related documentation. If I compiles, I ships. 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.
- mikeash 11y agoI don't think that analogy really works. If bridge designers were doing this, there would be massive outcry and we'd put a stop to it. We allow it to happen with (terrible) programmers only because the harm they do is pretty limited, and nobody's getting killed because of it.
- seiji 11y agothere would be massive outcry and we'd put a stop to it. 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.
- mikeash 11y agoThese are all because of people copy/pasting code from the internet?
- GPGPU 11y agoThere are probably 100x more servers sitting in server farms running websites (and burning power) than need to be because companies would rather hire 10 cheap Ruby or PHP programmers than one "expensive" Erlang/Elixer programmer. So there is some harm to bad programmers, even for non-critical websites.
- quartzkilla 11y agoI think the analogy holds. Software doesn't kill people ...until it does: https://en.m.wikipedia.org/wiki/Therac-25 https://en.m.wikipedia.org/wiki/Therac-25
- mikeash 11y agoSoftware obviously kills people sometimes. But I'm pretty sure that people who blindly copy/paste code from the internet into production systems don't.
- 11y ago