Alex Mueller on Software and Technology 
Monday, September 24, 2007

I am tired, I have just written roughly 50 new classes for a service layer and I want to commit them to the trunk. Everything builds, all my tests are stubbed out, and I believe each class and method is well named. Alas, I need to comment code so the most junior of developers can understand its intent.

Good comments are no substitute for bad code. I come from the viewpoint that if my class is too difficult to understand without comments, then it needs to be refactored. If my function name does not clearly relay its intent, what it takes and what it returns, then I need to rename it. Commenting needs to be prioritized on a return-on-investment basis. Making commenting mandatory will lead to sloppy comments. If you cannot comment your code, you are forced to write readable code, something I feel is much more important and useful.

It is getting late, and I want to check in my 50 classes. Thankfully, I installed Roland Weigelt's "GhostDoc." This free Visual Studio add-in makes generating XML documentation comments for C# more manageable. It is configurable too, so I can choose how I want my comment styles to appear, set hot-keys, and more. Check it out. It certainly makes commenting easier.

I would be interested to hear your opinions on commenting. Can you apply general rules to it? How much is too much? How much is too little?

Monday, September 24, 2007 6:02:32 PM (Mountain Standard Time, UTC-07:00) | Comments [3] | Design | Tools#
Saturday, September 29, 2007 6:15:27 PM (Mountain Standard Time, UTC-07:00)
I got half way through this post and was about to write "you need ghost doc." Seems you found it :P

I agree with your thoughts. If you need a comment to describe the code, there is something wrong...

Monday, October 01, 2007 10:47:28 PM (Mountain Standard Time, UTC-07:00)
Even worse is commenting code just to comment it...
Sunday, October 07, 2007 12:27:25 PM (Mountain Standard Time, UTC-07:00)
Extreme Programming is about a system of *supporting* practices.

You don't need to document things if you have good communication.
Pairing and swapping pairs is a way of sharing design ideas amongst
the team.

If your "juniors" arn't coming to you and saying what the heck are
these 50 classes? then you have a communication problem.

If you don't want to have a highly social, high feedback environment
you will get problems with understanding of intent. If that is the
case you do need other forms of communication to help with
communication of intent. Commenting / Wikis can be good secondary
communication tools. They are a lower form of communication though.
Keith
Comments are closed.
MuellerDesigns.net
Search
On This Page
The Split Personality of the Tester/Developer
Cross Site Scripting (XSS)
Creating files with FSUTIL
PowerShell Management Library for Hyper-V
Installing Windows 7
Installing Linux in Hyper-V
Internet Explorer 8 Release Candidate 1
PowerShell Documentation
Automate Daily Tasks with PowerShell
SketchPath XPath Editor
Software Testing - Revisited
Architecting Buildings and Software
NBCOlympics.com with Silverlight
Marker Interfaces and C# Attributes
Most Popular
JavaScript ReplaceAll Functionality
What is polymorphism?
What is composition?
Sorting with IComparable and IComparer
Applying the Observer Pattern in ASP.NET
MVP in ASP.NET
What is abstraction?
What is encapsulation?
What is a class?
What is inheritance?
Authentication in ASP.NET
Calendar Controls
XPathNavigator.CheckValidity new for 2.0
SQL Server 2005 Connection Issues
Auto-attach to process '[####] aspnet_wp.exe' on m...
What is an object?
FreeTextBox
VMWare and VPC
An Example of Reflection using C#
Changing File Ownership In Vista and Longhorn
Archive
Links
Categories
My Local Blog Map
Blogroll
About
Powered by:

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
MuellerDesigns.net

Sign In

Help Those In Need
The Hunger Site
Ronald McDonald House Charities (RMHC) of Western Washington & Alaska