Java : Java Stuff!!
Updated: 3/6/2004; 12:54:45 PM.

 

Subscribe to "Java" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Tuesday, March 11, 2003

Comments yeah...what are they good for....

I was always taught that comments are good...hell in school..if I didn't comment that I got a lower grade...So how does this jive with some of the popular terms such as "self-documenting code" or "if you write readable code you don't need comments". I know that in XP they say that your code shouldn't require comments. I say they are WRONG!! And here's why....

Before we pass judgement...Let's see why we need comments. There are two basic reasons for having comments

  1. To describe what the code does
  2. To describe why the code does what it does

In the first case...I agree that writing good..clean code may substitute for comments...and if you still feel you need comments attempt to refactor so that the code is clear.

However, in the second case comments are definitely necessary...If you are using a non-obvious algorithm to solve a specific problem they although people reading your code may know what it does they don't know why? In this case a comment can be helpful. Especially in XP where there is no code ownership, someone else may be changing your code at a later date (maybe even the developer who wrote the code)and not fully understanding the algorithm. This is a recipe for disaster...

Tell me...what's your policy....


5:19:51 PM    comment []

© Copyright 2004 Peter Ghali.



Click here to visit the Radio UserLand website.

 


March 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Feb   Apr