Captain Obvious commentaries

image1572-570x194.png

 

It was hard to write the code so we need to write good commentaries. Besides detailed commentaries are a characteristic for quality software right?

No.

To write a useful comment is a special art – but to comment on everything ends in something like this:

  /// <summary>
    /// Home Controller
    /// </summary>
    public class HomeController : Controller
    {
        /// <summary>
        /// Index Method
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        /// <summary>
        /// Guess what?
        /// </summary>
        /// <returns></returns>
        public ActionResult About()
        {
            return View();
        }
    }

The value of comments like this is almost zero – short of you tricked a special “Quality code Metric” or followed a rule. StyleCop & Co offer an easy way to create a rigid rule type.

Rules and “less is more”

A “we comment on everything” rule makes no sense at all and seduces people to create “wrong” comments. Comments have to explain the code – why is there this and this element. That it’s the “HomeController” class I’m able to found out by myself and I also know what a constructor looks like. But why do you run these tests? What’s the technical background behind this Code?

If you write to many commentaries for your code your project members won’t be very motivated to read them. Resharper is able to run smart Refactorings – but the commentaries need to be handmade and if nobody does this (because there are too many of them) they are nothing more than dead weight.

My recommendations for commentaries:

- Why did you develop your code like this? The how is already in the code

- Rules seduce to useless comments and they need additional time during the development and especially in the code support

- You need to agree on one language in your team. German/English mixture isn’t that nice

- Always keep in mind: Is the comment an additional value for the code? If not than you don’t need the comment. Don’t mind. (Commentaries are not a must have!)

If comments get to long…

In this case you might ask yourself if your code is too complicated. Countless lines of explanation may show you that your method has to many tasks.

Other opinions about this subject

Ayende Rahien and Jeff Attwood blogged about this (old subject) as well.

I’m interested in your opinion as well

What do you think? Comment on everything? Am I just too lazy for all the writing? Do you have any code comment rules?

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by Code Inside Team

Learn more about our team.

Comment on this post

Recent Posts

  • Json-Online-Tools: Viewer & Json2Csharp generator

      Wherever APIs are mentioned the JSON format I not far away. Since I’m using two tools regularly I would like to introduce you to them. JSON Viewer If you only see the JSON-Text you are usually not able to see the structure. With the help of JSON Viewer you can have an easy overview: ...

  • Windows Phone SDK & „System“-Icons

      Although the Metro Design focuses a lot on Typography Icons are still quite important. If you install Windows Phone SDK you will receive 36 Icons. You can find them here: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Icons Unfortunately many Icons you might know from the common applications are not integrated. Pedro Lamas extracted 99 additional Icons ...

  • image1830-570x194.png
    How can I figure out if my ADFS 2.0 works?

      I was working with ADFS 2.0 (“Active Directory Federation Services”) for a while when this simple question crossed my mind: How can I figure out if the connection between ADFS and AD “works”? Here is a simple test… What is ADFS? If you need some “position of trusts” beneath the AD-boarders you choose an ...

  • Subdomain vs. Subdirectory

      Better blog.mydomain.com or mydomain.com/blog? Good question! If got asked this question again via Twitter on the weekend so therefore I decide to share my experiences:   Choose a subdomain, if…. - You plan to offer “different services” which are “logical separated” on one domain - You are able to influence the subdomains without much ...

  • image1792-450x194.png
    Guide to Claim-Based Identity with the Access Control Service

    Microsoft published a free PDF about Claim-based Identity, Access Control Service and how to connect it to the remaining Microsoft world (Sharepoint, ADFS, Azure): Download-Link or MSDN Link I found the announcement today on the blog of Vittorio Bertocci. More information’s? If you want to get deeper into the subject you should risk a look ...

Support us