In an ideal code comments have no places.
- They make code look ugly. Even makes it unreadable.
- Too many comments makes it difficult to navigate code.
- They almost always convey outdated information. With outdated information, they might become confusing.
- One needs to read same code line twice. And the need to remember extra information while understanding the code.
Think, why should one write a comment? To tell certain information about
- a particular line of code
- about a block of code.
Can we express the same information via code.
- One should name the variable appropriately.
- Refactor a block of code in a separate method.
One more place where you will see comments is around the code which is no longer relevant. What should one do about such comments? JUST DELETE IT. Yes, just delete it. Version Control Systems remember it for you. Add if you want it work on it, just write TODO for it.
Happy Coding.