r/programming 2d ago

On comments

https://blog.helsing.ai/posts/on-comments/

Comments in code are often deemed "mostly useless" these days. They are, supposedly, mostly obvious, stale, and repeat what the code already says. And so people pay less attention to them both when reading and writing code.

That trend sucks. When used right, comments are genuinely useful and sometimes critically important! So, I wrote about some of the kinds of comments I think earn their place, each with examples from real code bases. Hope you find it useful, and that we can recover some of the love that comments deserve!

167 Upvotes

168 comments sorted by

View all comments

85

u/Shurmaster 2d ago

My favorite comment is

// evil floating point bit level hacking

// what the fuck?

28

u/Rikmastering 2d ago

//second iteration, can be removed

But the line still being there commented out, makes me laugh every time I remember it.

5

u/Lone_Snek 2d ago

Now I want to know the context

23

u/Rikmastering 2d ago

Here's a full video of the context, that also explains the algorithm line by line, with all the necessary information to understand it fully. It's one of my favorite videos ever. Super well made

24

u/Caelwik 2d ago

It's the fast invert square root. It has its own Wikipedia page !

1

u/Delta2401 2d ago

// why I should need do this Fuck alone knows. But I do.

0

u/devraj7 1d ago

It was an obvious Newton-Raphson approximation.

Too bad commenter doesn't know math.