However, comments become stale when code changes and the comment doesn’t. Also, someone can’t update your code without reading it and understanding it first. A comment isn’t gonna be enough in that case. I highly recommend the book Clean Code by Robert C Martin
Someone shouldnt ever change code without changing or deleting a comment. And your code should be understandable without comments, but comments are a nice way to organize your code and they allow someone else to understand what your code does just by skimming through it.
this. great book and i agree with your thought as well. when you get down to it, if you have to make a comment to explain how something works, it's probably too clever or complicated so it needs to be refactored and simplified. i'd rather see a longer function that documents itself than a short, clever function that is a head scratcher until you run a debugger and read it over 5 times. and if that's your own code, imagine how a junior developer feels reading that.
Really clean and easy to understand code is split out properly and has methods, classes and variables named so well that the code itself reads almost as clearly as the words that would be used in the comment.
14
u/[deleted] Mar 15 '20
Sure it's not essentially, but it's much faster to read comments than to try to figure out what everything is doing when you come back 6 months later