I have seen comments like: "Gets or sets is required flag" for properties like IsRequired. Now that is something I do not really do. I mean isn't it obvious?
I use XML comments on top of classes, methods and properties where get/set does something more than just getting/setting value. Apart from this, I comment before a block where complex processing is going on or where rather weird looking code is present.
Other reason for comment is that you dont need to go to code to see a description of a function. For example in VS you get the comment of your code in the intellisense. That help you to code more quickly that figure out what does the function by the name (if you are lucky and the name reflect the functionality.
you might find bugs in your own not previously commented code and blamimg / shaming yourself
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
I recently had a conversation with a cohort where he said, "gee, I wish I'd commented why I wrote this code this way!" I think everybody should learn to comment why and only "how/what" to supplement obscure algorithms. I include myself in that camp, as I hardly ever comment on "why". I'm going to try and discipline myself to do that for a couple weeks and see what I discover.
I am in the favor of region. Declare a region and within it you can do whatever you feel like. Which also is kind of territorizing your code. So we can look into that section. And yes commenting is also a must.
I've made a habit of commenting my code thanks to CodeProject. Preparing a source code for an article to be published in CodeProject is not exactly same as developing an end-user application. Readers may read the entire code and tried to understand line by line so comments are mandatory. Based on the viewers questions and suggestions for previous articles, I could decide what exactly should comment in the code of next article.
I initial and date my comments as a matter of habit... Many times has it saved me from the Spanish Inquisition!! (Look, the last time this function changed was 6/5/2008 - it can't have suddenly caused the problem you are referring to!!)
Quad skating his way through the world since the early 80's...
it can't have suddenly caused the problem you are referring to
You wouldn't believe how many times that has not been true for me. The problem is every piece of code relies on a certain set of assumptions. Over time, as operating systems or hardware changes, those assumptions may no longer be valid. Code that worked may stop working or break in subtle ways. Multi-threaded code is my favorite example. I've had code that worked correctly in a single CPU environment break when Hyperthreading was introduced, and then broke again in a multi-processor environment.