News for hackers. Stuff that matters.
Re:Why Not Comments by PlunderBunny on Tuesday September 10, 2024 @06:51PM (#41506407)
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.

Re:Why Not Comments by readthenotes1 on Tuesday September 10, 2024 @07:00PM (#41506506)
"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.

Re:Why Not Comments by PlunderBunny on Tuesday September 10, 2024 @07:58PM (#41506871)
It 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.
Re:Why Not Comments by g-b-r on Tuesday September 10, 2024 @08:14PM (#41506979)
Yeah, 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.

Re:Why Not Comments by kristiandupont on Wednesday September 11, 2024 @01:53AM (#41508393)
Not 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.

Re:Why Not Comments by readthenotes1 on Thursday September 12, 2024 @09:25AM (#41520672)
But what about a year later when someone's changed the code but not the comment?
Re:Why Not Comments by kristiandupont on Thursday September 12, 2024 @12:58PM (#41522963)
I 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.
Re:Why Not Comments by ykonstant on Wednesday September 11, 2024 @02:52AM (#41508693)
>when hen wrote the comment.

I've always said coding is a cottage industry!

Re:Why Not Comments by CRConrad on Thursday September 12, 2024 @03:10AM (#41518291)
Re:Why Not Comments by __MatrixMan__ on Tuesday September 10, 2024 @09:14PM (#41507275)
I've got no trouble with that perspective, but wouldn't a log message scratch the same itch, plus more?
Re:Why Not Comments by PlunderBunny on Wednesday September 11, 2024 @12:49AM (#41508110)
I'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.
Re:Why Not Comments by porridgeraisin on Wednesday September 11, 2024 @01:39AM (#41508316)
They 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", ...)