In my opinion, comments should not explain what the code does. There are a few reasons to use comments though:
After these considerations, if you need to add a comment to express what the code does, then your code is crap and you should improve it instead of adding a comment.
I like this quote from Kevlin Henney: "A common fallacy is to assume authors of incomprehensible code will somehow be able to express themselves lucidly and clearly in comments."
Yeah ! Well explained :)
Thanks, to be fair I wrote a few articles on clean code so I had time to practice ahaha
Hahaa greatt !! :)
As always, there is an exception: regular expressions.
Of course, we could write 20+ lines of code to replace a 1-line regex and make it more readable, but sometimes a regex really is the best fit for a problem. The downside is that they tend to be as legible as ancient Egyptian hieroglyphics. So those I comment what they do.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.