The past months, we have had a few (nice) threads about commenting source code. Methinks most can agree when I say it's an important issue.
In "Code Complete" by Steve McConell, there is quite a bit written on commenting. One technique that was explained, was that of PDL: 'Pogram Definition Language'. I gave it a try, and it worked quite well for me. I would love to hear your opinions of it.
I didn't read docs about PDL, just what McConnell had to say about it. To me it is straightforward: describe in simple terms, simple logic what your program does without using any language-specific idiom.
I tried it with one script I needed to create (you can find it here). Let me illustrate one subroutine:
McConnell said to copy the PDL as comments into the code, but to my personal opinion that gets unreadible. I think it partly is because perl is a very dense language, that explains itself to some extent. But the PDL provides something different, the logic minus language specifics.=head1 $a = interval( $source, $interval, $number_bins) Calculates inter-event interval histogram of the source (arrayref). Th +e $interval gives the maximum inter-event interval that should be counte +d. The $number_bins denotes the number of bins of the interval. =cut $PDL = <<'_PDL'; _interval_ extract arguments prepare return empty histogram unless the source has more than two items get the first item of the series as a reference walk over series assign current item to reference calculate difference between item and reference add the buffer to the histogram return the histogram _PDL sub interval { my $source = shift; my $interval = shift; my $interval_bins = shift; my @times = @$source; my $start_time = $times[0]; my @interval_histo = (0) x $interval_bins; return \@interval_histo unless scalar(@times)>1; my $prev = shift @times; my @buff = map { my $time = $_ - $prev; $prev = $_; $time} @times; buffer2histo( \@buff, \@interval_histo, 0, $interval, $interval_bins + ) if scalar @buff; \@interval_histo; }
PDL served me very well for the first draft. However, I needed to change some logic in second instant. During that rewriting stage, I just ignored PDL until I had it right. Only than I added new PDL for the changed routines. Afterwards, I changed some lines, as writing the PDL made some logic decisions more clear.
Are there any issues when using PDL for perl? Comments, thoughts, ideas? I'd love to hear them.
Jeroen
"We are not alone"(FZ)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Commenting: What about PDL?
by tilly (Archbishop) on Apr 10, 2001 at 03:34 UTC | |
|
Re: Commenting: What about PDL?
by Malkavian (Friar) on Apr 09, 2001 at 20:23 UTC | |
by jeroenes (Priest) on Apr 10, 2001 at 12:49 UTC | |
by tilly (Archbishop) on Apr 10, 2001 at 21:33 UTC |