Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this questionI reviewed some professional code written in Ruby and found no comments. The code was reasonably clear to read but not self-documenting. Should I expect professionally written Ruby code to have comments? Or, is there some Ruby doctrine that comments are not considered essential?
This issue isn't unique to Ruby.
Code comments should be kept to an absolute minimum, because they are usually not updated when the code changes, and become more misleading than helpful.
As you have already suggested, the best code is self-documenting and requires no comments.
Edit: to clarify, if you cannot reduce the code to remove the complexity, you must provide comments. This is rare in my experience, and usually only applies when external components don't behave as you might expect.
Matz, the creator of Ruby, states his philosophy here and there: "The source code is the documentation. It even states all the bugs correctly." And he probably means that for comments as well. I think many people who don't comment in Ruby source code are following his words. Whether for you to follow him is up to you.
I have also read some Ruby introductory websites saying that, whenever you feel the necessity to comment, that is an indication that you should split that routine as in individual method, and name it as you were to comment that part.
精彩评论