1

So far I understand that its good practice to XML comment a classes methods but is there a standard for how much you should use XML comments?

Should I be using them to document field variables, properties & constructors or is that just overkill?

Had a look about the web but can't see any hard and fast rules for this sort of thing.

Marc
  • 16,170
  • 20
  • 76
  • 119
cosmicsafari
  • 3,949
  • 11
  • 37
  • 56
  • 5
    No such thing as overkill. The easier it is to decrypt code, the better. I use `//` for local variables and XML comment methods, constructors (I use multiple constructors) and properties. – Bob. Nov 13 '12 at 18:23
  • Works for me, cheers bob – cosmicsafari Nov 13 '12 at 18:24
  • I think my code to comment ratio is about 1:1. Its aggressive, but consider if you read someone else's code, you'd rather have everything commented than nothing. – Bob. Nov 13 '12 at 18:25
  • We usually XML comment all methods, constructors, events, and properties. The only time we XML comment fields is when they are public. At the end of the day teams and people do whatever makes sense for them. – lumberjack4 Nov 13 '12 at 18:30
  • 4
    This should be on programmers, if on SE at all, as it's a subjective question. – Servy Nov 13 '12 at 18:31
  • Thanks folk, I'm used to working with PHP so the idea of an object viewer is new to me. Hence why i was wondering if there was a standard practice for the whole XML commenting idea. Im used to just // myself – cosmicsafari Nov 13 '12 at 18:33
  • You should read [coding without comments](http://www.codinghorror.com/blog/2008/07/coding-without-comments.html) as well – Patrick Nov 13 '12 at 21:02

1 Answers1

3

There are two reason to use XML comments opposed to plain English:

  1. If the comments follow the correct format they will show up in IntelliSense, meaning when I use your class I can see that int a is supposed to be the count or whatever the same way I see helpful info when I'm using .NET methods,

  2. If you use the XML formats Microsoft supports you can create html (or other formats of) documentation using SandCastle or similar third party utilities.

So, if you're taking the time to write comments, you may as well make them the XML ones that VS encourages.

NullUserException
  • 83,810
  • 28
  • 209
  • 234
evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115