Comments have two important roles:
6inThis kind of comment is useful only to someone who needs to understand
operational details. Often this kind of comment appears as an adjunct to a
``purpose'' comment (for example, at the start of a program or procedure,
see below) - but in this case it should be should be physically
separate, usually in a paragraph following the purpose comment.
Keep the issues separated, to help the two kinds of reader.
For example, to illustrate these ideas:
procedure Find(var Directory : Tel_Numbers; Item : Tel_No);
(* In: Directory, Item.
This procedure searches for the telephone number Item in the given
Directory. Note that the final entry in the Directory is indicated
by the global variable Top. A message is written out indicating
whether or not Item was found.
Uses linear search with a sentinel. *)
It is a useful practice to put a comment at the end of
each procedure/function body indicating which procedure/function
it is the end of. (Some programming languages enforce this!)
These comments should be brief, and certainly not on every line. The style of comments should again be to help the reader to understand the purpose of the commented statements; a comment which simply says what can be read from the program code itself is no use.
For example:
(* Now count cars into the car park *)
...
...
Level1:=Level1+1; (* One more car onto level 1 *)
...
if .... then
begin
...
end (* if *)
This is certainly helpful if the
compound statement is long and has many indented subcomponents; it is
obviously related to the practice of marking the end of
procedure/function bodies with a comment - but it is not always
obvious which if, etc. it is marking the end of.