News for hackers. Stuff that matters.
Re:8-bit number to binary string by mikeash on Thursday November 05, 2015 @10:40AM (#10513894)
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.

Re:8-bit number to binary string by acqq on Thursday November 05, 2015 @10:46AM (#10513930)
> 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

Re:8-bit number to binary string by Splines on Thursday November 05, 2015 @11:29AM (#10514232)
The 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.

Re:8-bit number to binary string by acqq on Thursday November 05, 2015 @11:43AM (#10514335)
> 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.

Re:8-bit number to binary string by seiji on Thursday November 05, 2015 @10:49AM (#10513958)
My 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.

Re:8-bit number to binary string by function_seven on Thursday November 05, 2015 @12:43PM (#10514811)
I'm sorry you have that job. Or, maybe congratulations if you're the consultant who comes in and makes bucket loads of money fixing other people's crap.

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.

Re:8-bit number to binary string by tertius on Thursday November 05, 2015 @02:21PM (#10515555)
I'm sorry but this is a false analogy [1].

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...

Re:8-bit number to binary string by seiji on Thursday November 05, 2015 @04:35PM (#10516265)
as scott adams says: I agree with your analysis of your hallucination.

"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?

Re:8-bit number to binary string by newobj on Thursday November 05, 2015 @01:19PM (#10515105)
yikes dude. go to bed, have a good rest, and i hope that you wake up in a better mood tomorrow.
Re:8-bit number to binary string by mikeash on Thursday November 05, 2015 @11:47AM (#10514364)
I 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.
Re:8-bit number to binary string by seiji on Thursday November 05, 2015 @01:01PM (#10514963)
there 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.

Re:8-bit number to binary string by mikeash on Thursday November 05, 2015 @07:12PM (#10517054)
These are all because of people copy/pasting code from the internet?
Re:8-bit number to binary string by GPGPU on Thursday November 05, 2015 @12:24PM (#10514640)
There 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.
Re:8-bit number to binary string by quartzkilla on Thursday November 05, 2015 @12:26PM (#10514665)
I think the analogy holds. Software doesn't kill people ...until it does: https://en.m.wikipedia.org/wiki/Therac-25
Re:8-bit number to binary string by mikeash on Thursday November 05, 2015 @01:39PM (#10515247)
Software obviously kills people sometimes. But I'm pretty sure that people who blindly copy/paste code from the internet into production systems don't.