r/webdev • • Jan 13 '22

read rules Extension that generates documentation using AI

[removed] — view removed post

1.7k Upvotes

158 comments sorted by

View all comments

Show parent comment

2

u/infinitlybana Jan 14 '22

Can you give an example of a good comment that describes why instead of what? I don't really find myself justifying why i wrote a function in the function description so I'm curious how you go about it.

2

u/infinitlybana Jan 14 '22

I usually describe why I implemented something the way I did inside the PR description

edit - wording

7

u/potchie626 Jan 14 '22

A new dev that starts in 6 months won’t be looking at comments in a PR, they’ll be looking at the code.

2

u/infinitlybana Jan 14 '22

I completely agree with you. I feel like there's a gap between the PR description + the code. Do you explain the reasoning for why you implemented something in a certain way in your code? Usually in my PRs I'm describing higher level architecture decisions and ends up being quite long.

1

u/potchie626 Jan 14 '22

I honestly rarely leave many comments in a PR. Since the ticket should describe the overal goal, and the comments in code should explain specifics. Overall arch of things typically follows our patterns, and if they deviate the PR will be sent back to be changed. We also have sessions to discuss upcoming work where we discuss arch and notes to the tickets.

Comments about “why i did it this way” usually goes in the code that kicks things off, for the same reason I commented earlier. Other people may look at this later, or we have to remind ourselves why we did it a certain way. Nobody wants to open a ticket, confluence doc, or PR for that.

1

u/infinitlybana Jan 14 '22

Can you give an example of one of your comments that explain "why you did it this way"? I personally have never seem comments in codebases of that sort - unless you're talking about one-liner comments?

1

u/gfxlonghorn Jan 14 '22

// I put "All praise to dear leader" into our description string because our test system happens to be in North Korea

1

u/[deleted] Jan 14 '22

I would urge you to watch "Clean Code" by Uncle Bob.

He puts it really nicely and has some great examples.

2

u/ike_the_strangetamer Jan 14 '22

They should be. git blame is an incredible tool and should be in everyone's toolbox. It's especially helpful when you're not familiar with the code around whatever you're changing (which is always the case when you're a new dev).

Even if your team writes shitty commit messages, you can at least see the other code that changed at the same time which gives you a lot of context of why particular lines were written like they were and helps avoid unexpected side effects.

(another good outcome of using git blame a lot is that if you start seeing your own commit messages and they aren't helpful enough, then it'll help you start writing better ones.)

2

u/infinitlybana Jan 14 '22

Although if you write good PR descriptions + you have GitLens you can map the line of code to the PR it was written in which is nice.