3 ms·
Not the person you are replying to, but I would say that: - The code 'tells you' what it does - The comment for the code tells you what the author intended it
by PlunderBunny 2y ago
Not the person you are replying to, but I would say that:
- The code 'tells you' what it does
- The comment for the code tells you what the author intended it to do.
The gap between the two is where bugs can be found.
- readthenotes1 2y ago"The comment for the code tells you what the author intended it to do." Not quite. The comment for the code tells you what the author of the comment understood the code to do when hen wrote the comment.
- PlunderBunny 2y agoIt could be that too, but I think that presumes an order - that the comment was written after the code. If the comment was written before the code, then it would describe what the author was trying (intended) to do. Which also implies an order of course.
- g-b-r 2y agoYeah, absolutely check who wrote a comment before relying on it It's luckily rare for people to add wrong comments, though (and those who do should be publicly fustigated). By the way, please never state something as it were the truth if you're not sure that it is. Saying "I think" is perfectly fine, and might save people days of investigation.
- kristiandupont 2y agoNot the comments I write. I don't write what the code does or even what "I understand the code to do". I explain choices, especially ones that the next developer or my future self is likely to misunderstand when looking at the code.
- readthenotes1 2y agoBut what about a year later when someone's changed the code but not the comment?
- kristiandupont 2y agoI would say that I have observed something like this about as many times as someone has changed some semantics in a way that a variable or function name is no longer correct. That is to say: probably a few times in 25 years, but nothing compared to how much value I have received from them.
- ykonstant 2y ago>when hen wrote the comment. I've always said coding is a cottage industry!
- CRConrad 2y agohttps://en.wikipedia.org/wiki/Hen_(pronoun) https://en.wikipedia.org/wiki/Hen_(pronoun)
- __MatrixMan__ 2y agoI've got no trouble with that perspective, but wouldn't a log message scratch the same itch, plus more?
- PlunderBunny 2y agoI've never worked in a company where the commit log message wasn't just a link/reference to something in a bug tracker. I feel like a 'what this block of code does' comment is different from 'what is this change, and why did I make it' commit message.
- porridgeraisin 2y agoThey meant logging-logs in the code itself: log.Debugf("Foo is: %#v", ...) //You think: this is probably filtering code log.Debugf("Foo without X is: %#v", ...)