I am a self-taught developer from Argentina currently living in Spain. I am passionate about improving my technical skills and helping others do the same.
In my opinion, comments should not explain what the code does. There are a few reasons to use comments though:
to express the developer's intent, why something was done in a certain way.
to describe API functionality (if the code is gonna be used by an external project or as part of a web service)
when performance is so critical that there is a reason to avoid abstractions.
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."
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.
I am a self-taught developer from Argentina currently living in Spain. I am passionate about improving my technical skills and helping others do the same.
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."
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.
Yeah ! Well explained :)
Thanks, to be fair I wrote a few articles on clean code so I had time to practice ahaha
Hahaa greatt !! :)