News for hackers. Stuff that matters.
Re:Best practices for writing code comments by janaagaard on Friday December 24, 2021 @04:55AM (#29672165)
> I write my comments in commit messages because those are valid forever.

Don’t they disappear when someone squash merges branch where a file is both renamed and changed (a lot)? Or, at least, when somebody decides to move to code to another repo, and doesn’t bother bringing the git history along.

Re:Best practices for writing code comments by zerocount on Friday December 24, 2021 @06:50AM (#29672845)
Yep. I make a commit on every little change and every team I've been on makes me squash them on merge.

Comments in Git commits are bad. Just comment the code and make sure the comments are updated while you're in the code. You can also look at them in a code review. The argument that they get outdated is easily remedied, but people just want to keep claiming they write 'self documented code.'

Re:Best practices for writing code comments by Zitrax on Friday December 24, 2021 @05:33PM (#29678412)
Git commit messages and code comments serve very different purposes, I don't see any reason to try to use one for the other or opposite.

To me both are important but for different reasons. I don't want to search the blame history of a line of code if a simple comment had been enough, neither would I want to primarily use code comments when bisecting.

Re:Best practices for writing code comments by u801e on Friday December 24, 2021 @09:56AM (#29674080)
> make sure the comments are updated while you're in the code. You can also look at them in a code review.

People will invariably forget to update comments and unless the comments show up in context lines of the diff associated with a change, it's likely that reviewers will overlook the need to change them.

Re:Best practices for writing code comments by Gibbon1 on Friday December 24, 2021 @04:39PM (#29678000)
You comment is a standard explanation for not having comments. Always makes me wonder why stale comments aren't flagged during code review? Seriously failure to update comments should eventually lead to constructive dismissal.
Re:Best practices for writing code comments by sokoloff on Friday December 24, 2021 @07:48PM (#29679247)
I don't think "constructive dismissal" is the phrase is you want there. (That's normally associated with employer wrongdoing or, at a minimum, mischaracterizing the terms of an employee's departure..)
Re:Best practices for writing code comments by jt2190 on Friday December 24, 2021 @02:15PM (#29676769)
I don’t understand. Can you not squash your commits and rewrite the message before you merge? Wouldn’t that preserve the message? (Trying to think of a scenario where it wouldn’t…)
Re:Best practices for writing code comments by johnisgood on Friday December 24, 2021 @07:27AM (#29673061)
I dunno if he really meant that, or just said he is explaining the added functionality in detail. I do explain in the commit message the feature I have just added.
Re:Best practices for writing code comments by AlexCoventry on Friday December 24, 2021 @01:56PM (#29676576)
Everyone has to be onboard for that to work. Lots of people just never look at comments because they don't trust them.
Re:Best practices for writing code comments by jt2190 on Friday December 24, 2021 @02:12PM (#29676743)
> … when someone squash merges…

It depends on who the “someone” is I suppose.

I typically squash my own commits, and as part of that I aggregate all of the commit messages into a single message with all of the relevant details (and leave out the “fixed typo” type stuff that’s not relevant.)

From the complaints that people are raising here there must be dev shops where someone else decides to squash a bunch of commits and throw away the messages.

Re:Best practices for writing code comments by cerved on Friday December 24, 2021 @05:39AM (#29672438)
squash merge is evil
Re:Best practices for writing code comments by usr1106 on Friday December 24, 2021 @02:59PM (#29677176)
The author should squash useless commits. A readable series of commits is put to review. At merging to a commonly used branch no more squashing.
Re:Best practices for writing code comments by cerved on Saturday December 25, 2021 @04:46AM (#29681866)
Why?

Why doesn't the author make commits that are not useless?

Why squash everything into a single commit? Why not 2 commits, 3, 5?

Re:Best practices for writing code comments by reidjs on Friday December 24, 2021 @12:23PM (#29675423)
I feel differently, why don’t you like it?
Re:Best practices for writing code comments by notfed on Friday December 24, 2021 @12:55PM (#29675838)
The above-posted scenario is a great reason to hate it. It's destroying developers' documented rationale for each change.
Re:Best practices for writing code comments by cerved on Friday December 24, 2021 @12:59PM (#29675896)
it destroys information for no good reason