Why are comments bad in coding?

Why are comments bad in coding?

Unnecessary comments create distractions Don’t interrupt that flow with comments that don’t bring any other explanation rather than the code itself. When other programmers read your work, they tend to plug their minds into that flow of yours. Consistently interrupted by redundant comments can create distractions.

Are comments bad practice?

Commenting code is on the generally-recognized list of code smells. But unlike most of the others on the list, comments are not always bad. Generally speaking, you should strive to minimize comments and let the code speak for itself, but it is just as important to include comments when the code cannot.

How are comments considered a code smell?

Comments are usually created with the best of intentions, when the author realizes that his or her code isn’t intuitive or obvious. In such cases, comments are like a deodorant masking the smell of fishy code that could be improved. The best comment is a good name for a method or class.

What’s the wrong with comments that…?

Answers without enough detail may be edited or deleted. A lot of people claim that “comments should explain ‘why’, but not ‘how'”. Others say that “code should be self-documenting” and comments should be scarce. Robert C. Martin claims that (rephrased to my own words) often “comments are apologies for badly written code”.

What’s the problem with comments in JavaScript?

There’s nothing wrong with comments per se. What’s wrong is writing code that needs those kind of comments, or assuming that it’s OK to write convoluted code as long as you explain it friendly in plain English. Comments don’t update themselves automatically when you change the code.

Why does commenting code just to comment code smell?

Commenting code just to comment code is a smell. Commenting code because you’re using an obscure algorithm that’s an order of magnitude faster saves the maintenance programmer (usually me 6 months after I wrote it) half a day of poking through the code to determine what it’s doing. // Dear me in the future. Please, resolve this problem.

Why do you put clarification comments in your code?

Clarification comments are intended for anyone (including your future self) who may need to maintain, refactor, or extend your code. Often, a clarification comment is a code smell. It tells you that your code is too complex. You should strive to remove clarification comments and simplify the code instead because, “good code is self-documenting.”