3 ms·
Isn’t the purpose of comments to make code understandable? If that needs a why it’s a why-comment. If it needs a what it’s a what-comment. Especially if cleve
by croes 10mo ago
Isn’t the purpose of comments to make code understandable?
If that needs a why it’s a why-comment.
If it needs a what it’s a what-comment. Especially if clever programming tricks are used. 6 month later you already forgot what the trick is and how it works.
- zero_shift 10mo agoYes, but some people have a Jihad against "what" comments - believing these should be elevated into the structure of the code itself, eg veryVerbosePainfullySpelledOutVariableNames or thisFunctionNameExplainsAWholeDomainConcept()
- croes 10mo agoI would like to see their version of https://en.wikipedia.org/wiki/Fast_inverse_square_root https://en.wikipedia.org/wiki/Fast_inverse_square_root
- Scarblac 10mo agoYes, but there are other ways to make it more understandable (like good names, idiomatic code, units that are neither too long nor too short) that are often preferable, because comments always have a danger of going out of sync with the code. The "why" is the part of the explanation that can't be deduced from the code.
- croes 10mo agoSometimes good names etc. don’t help. Think of this https://en.wikipedia.org/wiki/Fast_inverse_square_root https://en.wikipedia.org/wiki/Fast_inverse_square_root That definitely needs a what comment.
- Scarblac 10mo agoYes of course, sometimes there is no understandable way to write the code and comments are the best way. But there's also the case to be made that the comments that particular code needs are "why" comments. I can see what happens, but why does it work?
- croes 10mo agoWhy does it work or why was the code written? The article mentions the reason for the code which I would expect in the commit message