X

Documentation comment your C# code use GhostDoc at least

GhostDoc

Recently have been going through some old code to review the comments in them from other developers and what I find out is developers tend to have really bad comments & documentation in their code

Example:


public class Person 
{
   /// <summary>
   /// Constructor
   /// </summary>
   public Person() {}
   
}

From the above code it is obvious that it is the constructor but does the comment tell me anything? I understand that sometimes it may be hard to document or comment certain method, thus I really strongly suggest at least use GhostDoc

What is GhostDoc?
GhostDoc is a Visual Studio extension that automatically generates XML documentation comments for methods and properties based on their type, parameters, name, and other contextual information.

Here is the result of using GhostDoc on the Person Class


public class Person 
{
   /// <summary>
   /// Initializes a new instance of the <see cref="Person"/> class.
   /// </summary>
   public Person() {}   
}

As one can see Ghostdoc does a better job, don’t get me wrong GhostDoc still requires one to go through the comments here is an example where it tries to make sense.

 /// <summary>
 /// Riches the text selection changed.
 /// </summary>
 /// <param name="richTextBox">The rich text box.</param>
 private void RichTextSelection_Changed(System.Windows.Controls.RichTextBox richTextBox)

Riches the text selection changed. ????? As you can see it didn’t do one of the best job for this comment, but at least one can modify it and it may become “RichTextBox selection has changed event handler”

Personally I would recommend using the tool but just take it with a grain of salt and always check the documentation that it generates.

Categories: .NET C# Misc
Taswar Bhatti:
Related Post