Self Documenting code isn't

Graham Cox - Mar 4 '18 - - Dev Community

I know this is going to be a very controversial article, but I'm going to write it anyway.

Self Documenting code is not a good goal to aim for. Quite the opposite in my opinion.

Comments in code exist for a number of reasons. One of those is to tell what code does, and this is the kind that Self Documenting code seeks to remove. This is not a bad goal, because if the code needs comments to tell you what it does then it's too complicated.

Another form of comment, though, is the one that tells you why code does what it does. This is much more important that what because this is not self evident from the code itself. This can come down to code design decisions, product design decisions, large scale architecture decisions, or a myriad of other reasons.

Yet another form of comment is links to external sources. This can be issue tracker numbers, design documents, or many other things.

Finally, sometimes you really do need to document the big picture of how something works, because the entire algorithm is complex and it's not feasible for everyone to read all of the code to get the big picture overview.

So, whilst striving to make your code clean, obvious and easy to follow, don't go to far in removing all code comments because they have other uses too.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player