When I'm learning a language I write comments for myself. Notes about syntax, idioms, gotchas, and whatever else.
When I'm fixing a problem I leave XXX markers around to easily keep track of what I'm doing.
When I'm writing maintenance code I reference the ticket number, describe the problem or feature, and why we implemented the fix or feature the way we did.
You should never see the first two types of comments in checked in code, but I bet that I've probably saved later maintenance programmers hours of frustration with that last type of comment.
> Code should be almost as readable as a book. You should be to read without pausing too much as well as skimming.
I pause much more reading code than I do reading prose.
Trying to keep a lookup table of functions and variables in my head is much harder than reading a few lines of prose to let me know what's going on.
Comments should summarise what's going on, so that when you have a bug, you can jump to the right section to change.
> Comments are almost like an annotation in a book. So use them sparingly.
The way I think of it: Don't use comments to annotate your code. Use code to annotate your comments.
Sometimes you have to do bad stuff and you should stick a comment in there so that when you come back to that bit in code you are forewarned...
Think of it as hic seunt leones on old maps (here be lions for all the non-latin speakers out there...)
"Programs must be written for people to read, and only incidentally for machines to execute." - http://mitpress.mit.edu/sicp/front/node3.html