7.8. Comments
Create comment templates that are suitable for your team. For example, to internally document a subroutine or method, you might use something like: which might be filled in like so: Structured comments like that are usually better than free-form comments: # This method returns a hash containing the defaults currently being # used to initialize configuration objects. It takes no arguments. # There isn't a corresponding class attribute; instead it collects # the necessary information from the various attr_def attributes. There's # also a set_default( ) method. Templates produce commenting that is more consistent and easier to read. They're also much more coder-friendly because they allow developers to simply "fill in a form". Comment templates also make it more feasible to ensure that all essential information is provided, and to identify missing information easily, by searching for any field that still has a ???? in its "slot". Your team might prefer to use some other template for structured commentsmaybe even just this: In this version, the type of subroutine can be specified by retaining one of the four titles, and only the essential information is recorded: Note that it's particularly useful to indicate how the subroutine is expected to be usedeither with a Usage: field, or with a title like CLASS METHOD. In Perl, the sub keyword is used to declare normal subroutines, class methods, instance methods, internal-use-only utilities, as well as the implementation of overloaded operators. Knowing which role (or roles) a particular subroutine is supposed to play makes it much easier to understand the subroutine, to use it correctly, and to maintain it. A templated block comment like those recommended earlier should be used to document each component of a module or application. "Components" in this context means subroutines, methods, packages, and the main code of an application. |