|
-
March 23rd, 2011, 08:27 PM
#1
Javadoc comments
I'm confused as to the purpose of three javadoc comments.
Code:
/**
* What's this for?
*/
package group.subgroup
import some.stuff;
import some.extra.stuff;
/**
* And this one?
*/
public class Foo {
/**
* Finally, this one?
*/
//methods and their comments (i get how those work)...
}
And where do things like author, version, date, and copyright go?
-
March 24th, 2011, 08:57 AM
#2
Re: Javadoc comments
The first one is generally used for disclaimers, copyright info etc.
The second one contains the class description and often some example code on it's use. It is also where the author, version no. etc are normally put.
The third one could be either a comment for a declared variable, a constructor or a method. It all depends on what code follows it.
-
March 24th, 2011, 12:42 PM
#3
-
March 25th, 2011, 06:29 AM
#4
Re: Javadoc comments
Remember that comments in the body of the code should clarify or explain when the code itself is necessarily obscure. Well-written code should require a minimum of comments.
Good code is its own best documentation. As you're about to add a comment, ask yourself, "How can I improve the code so that this comment isn't needed?" Improve the code and then document it to make it even clearer...
S. McConnell
Programs must be written for people to read, and only incidentally for machines to execute...
H. Abelson and G. Sussman
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
March 28th, 2011, 09:15 PM
#5
Re: Javadoc comments
Alright, I went back and looked at the example I saw, and the third comment was not above a method or variable, but above another comment. It went like this:
Code:
public class Matrix {
/**
* The Matrix class throws a NonMultipliableException when two matrices cannot be multiplied,
* but catches it internally and returns null.
*/
/**
* Constructs a new Matrix with dimensions x by y.
*/
some constructor code...
other methods...
}
Why would that comment be inside the class? Wouldn't it be better where the class description was?
-
March 30th, 2011, 11:52 AM
#6
Re: Javadoc comments
Yes, it would, plus the comment will not show up in the right place should you do it like that when you create JavaDocs.
If you are going to do arbitrary comments inside of a class that do not go to anything, you are better served using regular multi-line comments instead of javadoc style comments.
Use
/*
*
*/
Instead of
/**
*
*/
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|