eff_i_g has asked for the wisdom of the Perl Monks concerning the following question:

Robed ones,

I'm going to embark on much PODing and I'd like to know if there is a "best practice" or guide in place for documentation, or more specifically, Perl documentation (and even more specific, argument syntax).

For example, it's common to surround optional arguments with square brackets. However, how does one convey that, say, a subroutine wants an array reference? (A) sub(\@array); (B) sub($array_ref); (C) sub([]); (D)? After re-reading that, I also assume it could be based on the context--if you know the exact name of an array you want (A or B), or just a quick list of things that normally aren't grouped (C).

That's just one example.

Normally I wouldn't be too particular about things like this, but my project is growing and there will be much POD spread across many files. I would love to keep these consistent and "best practice."

Just curious about what's out there,

Thanks!

Replies are listed 'Best First'.
Re: POD conventions
by stvn (Monsignor) on Mar 16, 2006 at 00:05 UTC
    I would love to keep these consistent and "best practice."

    Consistency is the best practice.

    I don't think you will find one particular way of doing anything in POD, but as long as you keep your project constitent with itself you should be okay. And consistency also has the side benefit of being easily "search-and-replace"-able :)

    -stvn
Re: POD conventions
by xdg (Monsignor) on Mar 16, 2006 at 04:40 UTC

    I prefer not to surround optional argument with brackets (or any other stuff that is typical of unix man pages) because those have real meanings in Perl. Likewise, I don't really like the pseudocode argument style of "perldoc -f" (i.e. all caps), though that's at least a sort of reference standard.

    I prefer to use actual perl structures, named in a way that indicates what they should contain, and then explain them in the actual Pod description. E.g.

    =head2 validate $is_valid = validate( \@args ); C<validate()> takes a reference to an array of arguments...

    But I'll echo what the others said -- consistency is the most important thing. You'll never get everyone to agree on a form to use, but as long as you're internally consistent, you'll minimize confusion.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      I agree with the "I prefer to use actual perl structures, named in a way that indicates what they should contain, ...". I would add the criteria/goal that the sample code should try to have a productivity advantage, i.e. allow cut-and-paste by the POD reader.
      Try to use the standard/common variable names found in the shop or application in the sample code. Examples: return code ($retcode, $rc), error return ($error_msg), etc. to make the sample code easier to quickly use.

      Also in agreement, \@array is far more meaningful than $arrayref or confusing []. If you are concerned about confusion (and particularly if more than one person is writing POD) - the first POD you write should be a style guide. Sounds redundant to some, but - Document how you Document, beforehand.


      I can't believe it's not psellchecked
Re: POD conventions
by lima1 (Curate) on Mar 16, 2006 at 00:53 UTC

    the first step to a good POD is a good template (e.g. Module::Starter::PBP).

    the second step is a good, intuitive API. if your API is good, a useful (meaning not too long and covering enough to start using your module) SYNOPIS section should be possible. I always look at that example code and then search for the functions I need.

    Explain that functions in detail: the parameters, return values and exceptions. Your question was probably how to do that right? It is not important as long as you write it down in a clear and consitent way. Maybe look at mature modules like DBI, CGI. Provide example(s). If the examples section for a function needs to be long to cover all functionality, you should probably refactor your code.

Re: POD conventions
by Argel (Prior) on Mar 16, 2006 at 00:26 UTC
    For what it's worth, I personally find POD interspersed within the code to be too distracting (e.g. to see the previous subroutine I have to scroll past all of the POD). Instead I prefer it when the POD is placed at the end of the file.
Re: POD conventions
by planetscape (Chancellor) on Mar 16, 2006 at 19:34 UTC