@Claudiu
When I write code that others will use - Yes. Every method that someone else can use (any public method) should have javadoc, at least indicating its obvious purpose.
@ Daniel Spivak
I carefully document every public method in every API class. Classes that have public elements but are not intended for external consumption stand out noticeably in the javadoc class. I also document every protected method in every API class, albeit to a lesser extent. This suggests that any developer who extends the API class will already have a fair idea of what is happening.
Finally, I will sometimes document private and batch private methods for my own benefit. Any method or area that, it seems to me, needs some explanation in its use, will receive documentation, regardless of its visibility.
@Paul de Vrieze
For things like trivial getters and setters, share a comment between them and describe the purpose of the property, not the getter / setter
int getFoo() { return foo; }
And yes, this is more work.
@VonC
When you break a huge complex method (due to a reason for high cyclomatic complexity ):
- one public method calling
- several private methods that are internal public steps
javadoc is also very useful for private methods, although this documentation will not be visible in javadoc API files.
However, this makes it easier for you to remember the exact nature of the various steps of your complex algorithm.
And remember: limit values or boundary conditions should be part of your javadoc.
Plus, javadoc is better than just "// comment" :
- It is recognized by the IDE and is used to display a popup when you move the cursor over one of your javadoc-ed functions. For example, a constant - a private static final variable - must have javadoc, especially when its value is not trivial. Example: regexp (its javadoc must contain the regular expression in its unescaped form, what is the target, and the literal matched by the regular expression)
- It can be analyzed using external tools (e.g. xdoclet )
@Domci
For me, if someone sees it or not, it doesn’t matter - I’m unlikely to know that some obscure pieces of code that I wrote do in a couple of months. [...]
In short, the logic of comments, not the syntax, and do it only once, in the right place.
@ Miguel Ping
In order to comment on something, you must understand this first. When you try to comment on a function, you actually think about what the method / function / class does, and that makes you more specific and clear in your javadoc, which in turn makes you write more clear and concise code, which OK.