DEV Community

Discussion on: "Do not comment on your code, it should be self-documented". Well... I don't agree.

Collapse
 
rishabh570 profile image
Rishabh Rawat

I believe there needs to be a balance. It's hard for me to believe that one can achieve the highest standards of readability in a production-level application with no comments. If written well, code will explain everything related to how stuff is happening. But based on my experience, there's always a need to document "why". And code often fails to achieve that without comments.

I think it's a quite known fact that real-world apps need to sometimes take paths that aren't intuitive, you would insert if-else in your function possibly destroying the single responsibility principle, because of business needs.

A comment explaining the purpose of what your code is doing is always welcomed.

Here's a talk by Sarah Drasner on Code comments, can check out if interested.