8

I would like to know which one is the best material that I can hand out to my students about "C# comments".

Germstorm
  • 9,709
  • 14
  • 67
  • 83
  • Take a look at this question I asked on SO about code documentation. There's some interesting insight in there that you may wish to repackage. http://stackoverflow.com/questions/288298/code-documentation-how-much-is-too-much – Robert S. Nov 21 '08 at 14:47
  • 1
    Without a doubt it must be [Strunk and White](http://www.bartleby.com/141/). – Ed Guiness Nov 21 '08 at 13:31

4 Answers4

13

Something that I read a while ago (and have lost track of where) is:

  • Beginners comment nothing
  • Apprentices comment the obvious
  • Journeymen comment the reason for doing it
  • Masters comment the reason for not doing it another way
Peter M
  • 7,309
  • 3
  • 50
  • 91
12

This Post by Jeff Atwood on his blog Coding Horror goes into the purpose of comments in general. Something you might think is 'duh' really isn't -- especially in the 'real world' when you see comments like the one below:

//Connect to the Database
Db.Connect();

And of course, there's the corollary to that post: Coding Without Comments.

George Stocker
  • 57,289
  • 29
  • 176
  • 237
2

Inside VS

Comments are relatively simple.

You can use for single line :

//This is a single line comment

You can use for multiple line:

/*
Multiple lines
*/

For method you can use :

    /// <summary>
    /// This is a description
    /// </summary>
    /// <param name="sender">Description of variable SENDER</param>
    /// <param name="e">Description of variable E</param>

Outside VS

When you go in the Project Property you can output all comments into XML and manipulate them.

Good practice

Comments should not be used to describe WHAT the code do but WHY or HOW if it's not clear.

Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
2

This is quite interesting to do with the xml comments: http://thoughtpad.net/alan-dean/cs-xml-documentation.html

These get read by sandcastle too... :o)

NikolaiDante
  • 18,469
  • 14
  • 77
  • 117