13

I'm a Perl programmer for a long time, but I always have problems with documentation in POD.

When I use POD comments in the code, the code is difficult to read. When I use POD comments at the end of file, there is the danger that the documentation is not in sync with the code.

I miss a documentation style similar to Java.

/**
 * @description
 * ...
 */

I look for an easier and more intuitive documentation style. Is there such a thing?

Jonas
  • 121,568
  • 97
  • 310
  • 388
ulli82
  • 155
  • 4
  • 11
    Changing the formatting in your editor may help with POD? I have the POD sections in both a differently coloured text and background (white text on grey, instead multi-coloured text on black), and the code is very easy to read for me. POD also has the advantage of being able to type `perldoc` from anywhere to read your documentation (and know it's the correct documentation from the actual version of the code running on that machine). – plusplus Jan 18 '11 at 10:06
  • 3
    Both the [Third](http://shop.oreilly.com/product/9780596000271.do) and [Fourth](http://shop.oreilly.com/product/9780596004927.do) Editions of *Programming Perl* were written in ᴘᴏᴅ. If one can write a 1200-page book in ᴘᴏᴅ, you would think one would be able to document a program or module with it. – tchrist Feb 20 '12 at 14:38
  • @tchrist Not according to [wikipedia](http://en.wikipedia.org/wiki/Plain_Old_Documentation) (the source of all that is true and good). Apparently, plain POD was not good enough; the [PseudoPod extension](http://search.cpan.org/~chromatic/Pod-PseudoPod-0.18/lib/Pod/PseudoPod/Tutorial.pod) was required. – John Oct 13 '14 at 23:58
  • 4
    @John What, you think I don’t remember what I used? :( Yes, the 4th edition used the PseudoPod extension, almost exclusively for tables. That doesn’t change the essential fact that is used POD. – tchrist Oct 14 '14 at 02:36

6 Answers6

9

A quick search found Doxygen Filter which purports to allow you to use Doxygen style comments (which are very close to Javadoc) to document Perl code.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
8

Well, POD's the accepted standard for publishing Perl documentation.

I do find it rather annoying to maintain as well; I've recently experimented with using Pod::Weaver to maintain the documentation and build it into Pod on release. It's a little bit tricky in that it's quite flexible in how you filter and build the POD, and could do with a little more documentation (in POD or otherwise). But seems promising. Still too early for me to give more of a judgement than that, but it seems promising.

Hope this helps

FalseVinylShrub
  • 1,213
  • 9
  • 10
  • Everything I write now uses Pod::Weaver. I get to have POD directives like '=method' and '=attr', so my code is easier to work with, and the documentation on CPAN is well-organized and contains other things like author and copyright information that I don't want to edit in every single file. Pod::Weaver is how POD should be used! – preaction Jul 13 '14 at 20:58
7

Why do you think the code is hard to read with Pod? Is the code hard to read with other code around it? Perhaps you're putting too much into a particular part of the code, instead of writing small methods, etc. Are you sure it's not your code that's hard to read?

You don't have to put all of your documentation at the end of the code. Pod is perfectly fine inline with code, allowing you to put the documentation for a subroutine or method right next to the subroutine or method.

Is there some other problem you have with Pod?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • 4
    Inline POD is even worse than sticking it all at the end! I prefer to make separate `.pod` files for anything requiring more than a little documentation. – friedo Jan 18 '11 at 17:33
  • Down voting because it's the classic "the problem is you" response. Yes, the problem is that this person can't read inline POD easily; and he's not unique. It's not perfectly fine for him, or he wouldn't be complaining. And let's not wrap up by throwing a Red Herring at the guy. I do like the separate .pod files suggestion by friedo. – Edwin Buck Jul 02 '18 at 15:54
  • I don’t think the problem is him necessarily. However, if I understood why it’s hard for him I might be able to help. That’s why I ask those sincere questions. – brian d foy Jul 03 '18 at 22:06
  • 2
    @briandfoy POD is very newline intensive. If I have a person that wants to get into details in Pod, I can't see the source code. If I relocate the pod under __END__ I can't see the Pod. Other languages suffer from inline documentation displacing the source code; but, POD's combination of being newline heavy (with requirements for blank lines everywhere) exasperates the problem. But, really I shouldn't be explaining this to you, you're brian d foy, a luminary within the Perl community. – Edwin Buck Aug 03 '18 at 14:22
  • Why do you think Pod is newline intensive? Which format do you think is not intensive? – brian d foy Aug 06 '18 at 16:12
  • Why do you think Pod is not newline intensive? The standard documentations for Java and Python don't require blank lines (those are the two I know best). Pod, on the other hand, unnecessarily requires blank lines on both sides of most `=command` directives. – Teepeemm Aug 10 '23 at 02:43
3

The only time I have had a problem with POD is when using a text editor that doesn't highlight it correctly.

Just like everything in Java this seems overly verbose:

/**
 * Returns an Image object that can then be painted on the screen. 
 * The url argument must specify an absolute  

{@link URL}. The name
 * argument is a specifier that is relative to the url argument. 
 * <p>
 * This method always returns immediately, whether or not the 
 * image exists. When this applet attempts to draw the image on
 * the screen, the data will be loaded. The graphics primitives 
 * that draw the image will incrementally paint on the screen. 
 *
 *  

@param  url  an absolute URL giving the base location of the image
 *  

@param  name the location of the image, relative to the url argument
 *  

@return      the image at the specified URL
 *  

@see         Image
 */
 public Image getImage(URL url, String name) {
        try {
            return getImage(new URL(url, name));
        } catch (MalformedURLException e) {
            return null;
        }
 }

When compared to the equivalent Perl.

=item getImage( url, name )

This method always returns immediately, whether or not the 
image exists. When this applet attempts to draw the image on
the screen, the data will be loaded. The graphics primitives 
that draw the image will incrementally paint on the screen. 

url must be an absolute URL giving the base location of the image

name is the location of the image, relative to the url argument

=cut

sub getImage{
  my ($url,$name) = @_;

  ...
}
Brad Gilbert
  • 33,846
  • 11
  • 78
  • 129
  • 5
    It would be nice if we had a richer doc convention so we could recognize the parts of the docs, such as the params. – brian d foy Feb 20 '12 at 17:55
1

You might want to take a look at Rinci. Examples of applications which use this: File::RsyBak, Git::Bunch, App::OrgUtils.

Here's how you document modules. You declare %SPEC in your module and put documentation inside it. Each function gets its own key. There are predefined fields. Localization is supported. The formatting is done in Markdown. An example:

$SPEC{':package'} = {
    summary => 'Module to do foo',
    "summary.alt.lang.id_ID" => "Modul untuk melakukan foo",
    description => <<EOT,
Blah...
...
EOT
    links => [...],
};
$SPEC{func1} = {
    summary => '...',
    description => '...',
    args => {
        arg1 => {
            schema => ...,
            summary => ....,
            description => ...,
        },
    },
    examples => [...],
    links => [...],
    ...
};

Instead of using Java- or Perl 5 style of putting documentation in "comments", it uses data structure directly available to the programs. (Note that Perl 6 is also going this way.) Think of it as Python docstring gone crazy (or structured).

There are tools to generate POD, text, HTML from the metadata (spec). Aside from documentation, the metadata is also useful for other things like argument validation, command-line interface, etc.

Disclosure: I'm the developer.

Steven Haryanto
  • 741
  • 5
  • 13
-2

Myself, I often find wanting to reproduce code entries to documentation. Yet to find how I can trick POD to read the code when podding whilst letting the code execute whilst parsing. Do I really have to settle for this:

=head1 Variables

use vars (%V &C)

=cut

use vars (%V %C)

=head2 Constants

$C{hashConstant1} = "/path/to/file"

=cut

$C{hashConstant1} = "/path/to/file";

=head2 Variables

$V{strVar1} = undef

=cut

$V{strVar1} = undef;

Then again, most languages require the double typing to document.

Oldskool
  • 34,211
  • 7
  • 53
  • 66