I've seen past discussions on perlmonks which deal with commenting style. I realize that at some point this ends up being a personal preference with consideration for consistency and conciseness being, umm, concerns. (Alliteration mostly unintentional :)

Nonetheless, I'd like to get a few opinions from the perlmonks community about a "new" commenting style which I worked out last night. As you can guess from looking at the following snip, I was reading a man page when writing up the comments.

I ended up with what I considered a well-commented method, but looking at it now I think it might just be too durned wordy. Reactions welcome.

# NAME # dump_subtable() - dump a subtable # # SYNOPSIS # dump_subtable ( scheme => $SCHEME, @OPTIONS ) # # DESCRIPTION # dump information from a subtable stored within invokant. # Initialisation via init_subtable() is performed if the # table described by $SCHEME is uninitialised. Returns an # array reference to the dumped information. (See HACKER # INFO, below.) $SCHEME is a Unihan.txt encoding scheme # descriptor, eg kBigFive or kGB0. # # OPTIONS # See EXAMPLE for an example of how to use the advanced # features of this method. They are: # # sorter => $CODE_REF # sorter_args => \@ARGS_FOR_CODEREF # # EXAMPLES # # anonymous sub for sorting # my $sorter = # sub { my ($ar_sortme)= shift(@_); # my ($fld)= shift(@_); # my @ret = sort { # ${$a->[$fld] cmp ${$b->[$fld]} # } @$ar_sortme; # \@ret # }; # end sorter sub # # # dump and sort the table by kBigFive value # my $ar_sorted = # $table->dump_subtable( scheme => 'kBigFive', # sorter => $sorter, # sorter_args => ['1'] ); # # # do something useful with the dumped table # foreach ( @{$ar_sorted} ) { # print ${$_->[0]} . "\t" . ${$_->[1]} . "\n" ; # } # # BUGS # This isn't terribly useful on multi-key $SCHEMEs, such # as kDefinition or kMandarin: this is due to a limitation # in how the table is parsed in the constructor. # # HACKER INFO # Values stored within the array reference are arrays of scalar # references, i.e. # # $ar_dump = $unihan->dump_subtable ( scheme => 'kBigFive' ); # # $ar_dump->[0] is now structured as # # $ar_dump->[0] = [ \$unicode_scalar, \$scheme_value ]; # sub dump_subtable { my ($self)= shift(@_); my (%args)= @_; my $hr_subtable = $self->{ $args{scheme} }; if ( not defined %$hr_subtable ) { my $init_ok = $self->init_subtable( %args ); die "dump_subtable() unable to auto-init subtable ", $args{scheme} +,"\n" unless $init_ok; $hr_subtable = $self->{ $args{scheme} }; } my @dumped; while( my ($subtable_key, $sr_uniscalar) = each %$hr_subtable ) { push @dumped, [ $sr_uniscalar, \$subtable_key ]; } defined $args{sorter} ? ref $args{sorter} eq 'CODE' ? return $args{sorter}->(\@dumped, @{$args{sorter_args}} ) : do { warn "dump_subtable() - sorter arg not a coderef. " . "Returning unsorted data.\n"; return \@dumped; } : return \@dumped; }

Please let me know: too much commenting for your taste? How well do you think the man-page style lends itself to code commenting?

post scriptum: this is part of a work-related module for parsing the Unihan.txt files; when complete, I might post the module provided my employer approves.

blyman
setenv EXINIT 'set noai ts=2'

Edit ar0n -- Added readmore tag


In reply to Am I over-commenting my code? by belden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.