diff --git a/JAVADOC_GUIDE.md b/JAVADOC_GUIDE.md new file mode 100644 index 00000000000..8001abda248 --- /dev/null +++ b/JAVADOC_GUIDE.md @@ -0,0 +1,99 @@ +# Javadoc Guidelines + +Javadoc is the main tool for documenting code written in Java. It is not the only documentation method, though - there are also block comments (`/* ... */`) and line comments (`// ... `). And, of course, there is external documentation - presentations, readme files, etc. Each documentation method has its own target audience. External documentation works well for onboarding developers. Block and line comments work well for addressing maintenance programmers (hopefully, a future you). Javadoc was created mostly for addressing client code programmers - people that write code that uses the documented code. +A Javadoc comment (`/** ... */`) is always attached to an element of the code. + +## Style guide +First and foremost, consider your audience. People mostly read the Javadocs when they are using the code as a black box, so describe what the documented artifact does from a client code's point of view. The description should be accurate, but short. The first sentence should be a summary - it's not just a good idea, it's the sentence copied by the Javadoc tool into summary tables at the top of the each Javadoc page. E.g., the table at the project overview page contains the first sentence from the Javadoc comment of each package. Note, however, that the end of the first sentence is detected by looking for the first period followed by a white space. Thus, abbreviations such as "e.g." would be considered as terminating a sentence. The standard workaround is to omit the last period, i.e. "e.g". + +Subsequent paragraphs may include references to the implementation, if needed. Describe the current state of the code, not its history. While Javadoc allows embedding links to external resources, do not rely heavily on these, as they can change. When a diagram would do a better job than text, consider using ASCII drawings. + +Javadoc supports links and formatting using HTML and specialized Javadoc tags, written `{@tagName tagParameter}`. The full list of Javadoc tags is maintained at the [Javadoc main page](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html). Important tags include: + +* `{@code javaCodeGoesHere}` for adding inline code - very important when referencing code that has generics, since Java's type parameter notation (`List`) will confuse the HTML parser unless escaped. +* `{@see reference}` a link to another class, method, or field in the documentation, appears at the end of the Javadoc comment. +* `{@link className}` same as above, but inline. + +As for the HTML tags, try to stick with the textual formatting ones (``,`
    `,``...), and avoid using structural ones (`
    `, `