Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Preferred method of documentation?

by jplindstrom (Monsignor)
on Oct 05, 2004 at 22:07 UTC ( #396796=note: print w/replies, xml ) Need Help??

in reply to Preferred method of documentation?

This is an example of a well documented method:

=head2 insertRows($nameTable, $raRow) Insert the data in $raRow (array ref with hash refs (key: field name, value: field data) into $nameTable. Return 1 on success, else 0. Die on fatal errors. =cut sub insertRows { my $self = shift; my ($nameTable, $raRow) = @_;

It describes the interface to the method. So you don't have to read the code to know how to use it. But you need to keep it in sync with the implementation, so the POD should be next to the method (Locality breeds Maintainability).

If you write the interface description before you start coding the method, chances are that you'll think one more time about edge cases, error conditions and stuff like that. Personally I find that a very useful way of organizing my thoughts before diving in.

Names of classes, variables, and methods should be meaningful and consistent. That way you don't need so many comments. Try to avoid abbreviations.

I find it useful to include the "domain specific data type" in the variable name to indicate what it contains, especially when using dynamically typed languages.

$timeout vs $secondsTimeout $table vs $nameTable $workspace vs $dirWorkspace

When you do comment, note the why, not the what. Write down assumptions, thoughts and non-obvious design decisions.

Having said that, it is ok to say what a regexp does, because it's often not obvious. It's useful to provide a sample of what you're trying to match. Alway use /x to make it more readable.

If you look at CPAN, each module has a SYNOPSIS section with short examples. These are very powerful.

Apart from all other benefits with unit tests, they also provide great hands-on documentation, like a SYNOPSIS on steroids.


Replies are listed 'Best First'.
Re^2: Preferred method of documentation?
by radiantmatrix (Parson) on Oct 06, 2004 at 15:38 UTC

    I most wholeheartedly agree with the parent. I'd like to add, however, that a POD section granting an overview of the module is most helpful as well.

    Poke around on the CPAN docs -- many of the modules there are well-documented. Combine that style with that of jplindstrom above, and you have superb documentation that is both in-code and extractable using any one of the pod2 tools.

    The existence of pod2html also means that your documentation will be intranet-publishable, which looks great to your project manager.

    require General::Disclaimer;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://396796]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2021-10-20 05:05 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (79 votes). Check out past polls.