When I started my carreer, I was tasked with (correctly) commenting on every module I write. An assignment of what the method does, how its parameters are used, and what to expect in response, etc.
Then, with almost two years, I began to visit outdated codes with misleading and / or useless comments. And in this process, I used them to remove code from the database.
In my recent work, my project manager instructed me not to worry about leaving comments at all, and suggested I rather rely on unit tests to leave the outline of the code I'm writing. I agreed since I tested this code over time, but the comments do not stay up to date, and then it becomes quite misleading.
Recently, I read Martin Fowler's refactoring book to extract a method wherever we see the opportunity to leave some comments. So leaving comments in modules is really an outdated thing now?
Just to summarize: According to my experience, we should not leave comments and, rather, accept the following two options: 1) The extraction method. 2) Unit Test to support module intent.
So, should we always avoid commenting and rely on two options? or do we have other alternatives? Please share your opinion.
Thank you for your interest.
source share