Adam Bien's Weblog
How to JavaDoc (efficient and maintainable) - 6 steps
Most of the JavaDoc comments are worthless. They describe redundantly already existing information and obvious facts. Many developers are indirectly forced (by e.g. QA) to write dumb Javadoc, only to increase some metrics. However this approach is really expensive, because:
- Someone has to write the JavaDoc
- ...and even worse - in the mainainance phase all developers are forced to filter out relevant things and ignore worthless information
The classic sample is:
/**
* This is a setter which sets the name
@param name - the name to be set
*/
public void setName(String name) {...
The already existing information from the method's signature is replicated to the javadoc. In my opinion such a javadoc is superfluos, every java developer knows what getters and setters are. The same anti-pattern is often applied to document other elements - not only obvious Java Bean "components".
Instead of writing superfluos documentation, you could also introduce a new Javadoc tag or annotation to mark such use cases e.g. @Obvious. In this particular case the QAs should be happy with the doc coverage and developers could silently ignore the doc.
Really good javadoc should be written accoding to the following rules:
- Document the background knowledge, the intention and not the result
- Try to capture the concepts in a central place (e.g. wiki) - and only reference to the contents
- Document obvious facts with marker tags - don't describe them over and over again (be DRY) [see Marker Annotation in p4j5]
- Include in your documentation samples, how-to etc. (source code rules)
- Don't allow default javadoc comments generated by the IDE
- Sometime "No Doc, is the Best Doc" - try to minimize the amount of documentation and describe only the key concepts.
Posted at 12:26PM Oct 30, 2007 by Adam Bien in Java EE 5 Architectures And Idioms | Kommentare[8]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices


When coding Java Beans and Entity beans, my big pet peeve is that I document (and annotate) the private fields, and there is no way to just absorb that documentation for the getters/setters. Since private access is typically not documentated by JavaDoc, this forces users to provide docs for getters and setters. And I hate that I need to document the same thing 3 times. Javadoc needs a strategy to deal with this problem.
Gesendet von Anthony Whitford am October 31, 2007 at 09:11 PM CET #
You mean 'intention', not 'intension'.
Gesendet von Anonymous am November 01, 2007 at 12:11 AM CET #
Your system time is wrong.
Gesendet von Anonymous am November 01, 2007 at 12:13 AM CET #
The @Obvious annotation is not a bad idea at all! :D
Gesendet von Paris Apostolopoulos am November 01, 2007 at 10:39 AM CET #
Anonymous,
1. I corrected intension -> intention. Thank you very much.
2. I hope no my, but my server's system time is wrong. I will check it - thanks.
Gesendet von Adam Bien am November 01, 2007 at 11:43 AM CET #
Paris,
thank you for the nice comment - request a beer at the next J1's after dark :-),
cheers,
adam
Gesendet von Adam Bien am November 01, 2007 at 11:44 AM CET #
Anthony,
you are right. But why not document the private fields only? Getters and setters are just redundant. I go in most cases further and use my own annotations to provide additional meta data.
In most cases I try to built more fluent domain objects and get rid of getters/setters...
thanks you for the comment
Gesendet von Adam Bien am November 01, 2007 at 11:47 AM CET #
>mainainance
is a misspelt word
Gesendet von anon am November 02, 2007 at 06:44 PM CET #