When i started my carreer i have been instructed to (properly) comment each and every module that i write. Instructing what a method does, how its parameters are used, and what to expect in return etc.
Then with almost 2years of doing so i started visiting legacy codes with misleading and/or useless comments. And in the process i used to remove them from the code base.
In my recent job my project manager instructed me not to worry about leaving comments at all, and suggested to rather rely on unit tests to leave a blueprint of the code i write. I agreed since i have experienced that code changes with time but comments do not stay up to date, and then it becomes rather misleading.
Then recently i read in Martin Fowler's Refactoring book to extract method wherever we see scope of leaving some comments. So is leaving comments in the modules is really an obsolete thing now?
Just to summarize: As per my experience, we should not leave comments and rather take the following two options: 1) Extract method. 2) Unit Test to support the intent of the module.
So, should we always avoid leaving comments and rely on above two options? or do we have other alternates also? Please share your opinion.
Thanks for your interest.