On this page:
Commenting
Formatting
7.7

Documentation

Commenting

It is a really good idea to write comments explaining your design and purpose. This allows you and anybody other using your code to understand what it is doing, how to use it and how it has been designed and implemented.

It is a good idea to abide by the following conventions:

A good rule of thumb is to assume that the audience for your comments is not you, but other designers/programmers who will use your code. If the language is such that only you can understand it fully (because you implemented it) revise the comments.

Formatting

Documentation is critical to making code understandable, readable and usable. As programmers we are both producers and consumers of documentation. Any good code base comes with copious and helpful documentation. For example “official” Java documentation is available online. You can read about the String class that we used above here.

Java comes with an in-built tool that helps you generate such html web pages from documentation written in your Java code. This tool is called Javadoc. This tool “reads” your comments and converts them into html. You can use specific formatting commands within your comments to facilitate generating pleasing documentation. In addition to the Javadoc-specific annotations (like @param, @return, etc.) Javadoc can handle any HTML syntax. This means you have the power of HTML at your disposal to format your documentation suitably.