Lurker News
Preferably an elegant snippet rather than an entire (well engineered) codebase.

Comments (380) 116 threads

Show all comments

Showing thread 4 of 116

vatys#
This is still one of my favorites. In a list of magic numbers, sorted by magic-ness, 0x5F3759DF would sit pretty high.
jmcgough1 reply#
IIRC Carmack didn't write that code, as brilliant as he is.
dkersten#
It even says that he didn’t write it in that wikipedia page.
hwillis#
I wonder which one used less energy in 1999?
chii2 replies#
it's the antithesis of maintainable code. But given that one is unlikely to want to change from calculating the inverse square root to inverse cube root or any other variation....
enriquto2 replies#
I disagree strongly. This code is very maintainable: it does not have dependencies, it is trivial to test, it is wickedly short, and with the appropriate comment there is no confusion regarding its purpose. Also, its field of applicability is clear from the context: replace this code with a call to fsqrt if you happen to have a fast hardware implementation of it. It is the most easily maintainable code, ever!
fteem#
By "the appropriate comment" you mean, and I quote:

"// what the fuck? "

chii3 replies#
the one maintainability metric, and i think is the most important one, is whether it's easy to modify (to make it do something slightly different).

You'd be hard pressed to write an inverse square cube without basically rewriting the whole function. There's nothing that can be reused. The only saving grace is that it is side-effect free, so replacement is trivial, unlike a lot of other code that's not maintainable.

Continue this thread — 3 replies

naikrovek#
it's a NUMBER - there's zero maintenance required for a number of constant value.
lbj1 reply#
I came here to post this. Remember back in the day when it was wildly discussed. Still impressive to this day.
quaquaqua1#
And it also made the guys a ton of money :) They found a way to take something useful in theory and other practical applications and use it to make something never before seen for the massmarket. That one magic number alone is responsible for a good portion of his net worth and of course his Ferrari
fxleach#
The most beautiful piece of code you've ever read contains a magic number with the comments "evil floating point bit level hacking" and "what the fuck?"... you're a madman.
QuincyJazz#
How do I get a job in /this/ area? I couldn't care much to do JavaScript programming, but this is awesome.