Useful and Useless Code Comments

Jim Nielsen:

If somebody says a comment isn’t adding any value, I would ask: to whom?

Personally, I’ve never liked the advice that writing obvious comments is bad practice—probably because I write obvious comments all the time.

Jim showed …


The post Useful and Useless Code Comments appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

Jim Nielsen:

If somebody says a comment isn’t adding any value, I would ask: to whom?

Personally, I’ve never liked the advice that writing obvious comments is bad practice—probably because I write obvious comments all the time.

Jim showed off some examples of “code comments that are at the same level of fidelity as the code itself.” Those are the hardest calls with code comments.

// this function adds two numbers
function add(a, b) {
  return a + b;
}

Easy to point at that and call it not useful. I tend not to leave this type of comment, but it’s fair play for Jim to question that. Comments can be used for a wide swath of people whom may at some point interact with that code, so why gate-keep it?

[…] comments can serve a very different purpose when they’re being read vs. when they’re being written. Those are almost two different kinds of activities.

I’d add they serve a different purpose when re-visiting old code vs actively working. Also different when you’re trying to code review versus directly contribute.

Direct Link to ArticlePermalink


The post Useful and Useless Code Comments appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-06-16T19:08:33+00:00) Useful and Useless Code Comments. Retrieved from https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/

MLA
" » Useful and Useless Code Comments." Chris Coyier | Sciencx - Wednesday June 16, 2021, https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/
HARVARD
Chris Coyier | Sciencx Wednesday June 16, 2021 » Useful and Useless Code Comments., viewed ,<https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/>
VANCOUVER
Chris Coyier | Sciencx - » Useful and Useless Code Comments. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/
CHICAGO
" » Useful and Useless Code Comments." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/
IEEE
" » Useful and Useless Code Comments." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/. [Accessed: ]
rf:citation
» Useful and Useless Code Comments | Chris Coyier | Sciencx | https://www.scien.cx/2021/06/16/useful-and-useless-code-comments/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.