DEV Community

Discussion on: Self Documenting code isn't

Collapse
 
pavlosisaris profile image
Paul Isaris

Many often believe that writing comments is an absolute waste of time, and that our only concern should be to have as clean code as possible.

I am a great fan of comments that focus on why or how, instead of what, and here lies the big distinction:

On the one hand, what a piece of code does, should be apparent from the code itself. Too many lines, difficult to understand syntax or poorly named variables are all signs of poorly written code.

On the other hand, why or how this code does a specific thing is a matter of the business logic of the application, and should be documented.

One cannot expect from a developer that opens a file to have a full grasp of the app's business logic.

Keep in mind though, that clean code means clean comments too and also requires extra effort to refactor and keep these comments up-to-date as well. :)