Ask HN: Any resources to learn how to effectively use commenting?

2 points by rankam ↗ HN
The Minecraft clone in C thread a couple of days ago had a discussion about commenting and it got me thinking about the fact that I don't know how to effectively use comments while writing code (I'm mostly self-taught and don't work for a tech company, yet). Does anyone have any tips or know of good resources where one can learn this?

3 comments

[ 36.1 ms ] story [ 1072 ms ] thread
Comment your own word what you want to say..

@ noizyoyster.com

"Clean Code" by Robert C. Martin may be what you're looking for.

Basically: express yourself in code. If you feel that some part of your code needs commenting, ask instead if it's possible to rewrite the code so that it is self explanatory. (The book goes into much more detail about this and more, of course.)

Example of "bad" code:

  // days since initialization
  int d;
Better code:

  int daysSinceInitialization;
Excellent! Thanks - I'll definitely check it out!