How Comments
A third type of comment is a "how" comment. These are for libraries and reusable
modules, and tell the reader how to use your code with their code. The Java
"doc" (or "API") comments for Java SE is an example of this. Such docs are
usually extracted from comments in the source code.
"How" comments are used to describe how to use the methods, fields, and classes
of your code. Generally, only public and protected methods and fields need
these, but they never hurt to include on private methods too. How comments
might describe method argument types and ranges, return value type and range,
method semantics, pre- and post- conditions, and use cases (example code).
They can include warnings (such as this method is not thread-safe), examples,
and references to other documentation. What and why comments are generally not
included in such API docs.
The how or API comments (also called doc comments) are specially treated in
Java, and are converted to HTML using the tool "javadoc". You can control
how that is done. Note this tool also examines the code itself, not just
the comments, to produce the API docs. How to use that tool and use proper
doc comments is beyond the scope of this post, but there are plenty of
resources on this topic available on the Internet, for example:
<
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html>.
How comments should be considered required on all public and protected classes
and members of classes.
Feedback Welcome!
--
Wayne