DEV Community

Discussion on: My take on commenting code - Explain why, not how

Collapse
 
andrewbaisden profile image
Andrew Baisden

Without commenting we would probably get lost in an unfamiliar codebase.

Collapse
 
nombrekeff profile image
Keff

Interesting, in which way would you say they help you navigate codebases? Have you ever felt the opposite way in any codebase?

Would you mind sharing some of these comments so we can better understand what you mean?

Collapse
 
andrewbaisden profile image
Andrew Baisden

Sometimes it's not always obvious what a block of code is doing. Every developer has their own way of setting up a project architecture. So commenting can help to get someone up to speed if onboarding them with another developers help is not an option.

Constructive comments are always welcome. The VS Code extension Better Comments is a good example of comments done well.

Thread Thread
 
nombrekeff profile image
Keff

Ohh okay, I see where you're going. I have to agree. This is in part what I was referring with explaining why you do something and explaining things code can't explain. Context on how a project is architected and why things are done in the way they're done. I also welcome these kinds of comments, and write them myself. I have no problem with them. My issue is mainly the comments explaining obvious or convoluted code, that could be better of just by refactoring and naming stuff correctly

For me these types of comments fall just in the line between code comments and doc comments.

Cheers, and thanks for the addition!