A long time ago, in a node far, far away, a fellow Monk pointed me at the Perlish Coding Style. For those not familiar, the PCS is all about having a left column that clearly indicates program structure. To shamelessly steal the first example from the site above:
; sub capture (&;*) { my $code = shift ; my $fh = shift || select ; local $output ; no strict 'refs' ; if ( my $to = tied *$fh ) { my $tc = ref $to ; bless $to, __PACKAGE__ ; &{$code}() ; bless $to, $tc } else { tie *$fh , __PACKAGE__ ; &{$code}() ; untie *$fh } ; \$output }
Certain things about this appeal to me, but I can't help thinking "I'd never use this for published code", and the proponent of this style agrees with me. However, I have found one piece -- the idea of the semicolon as a separator rather than a terminator -- to be useful when debugging.
Essentially, I use the leading-punctuation style encouraged in PCS to mark code that's inserted for debugging purposes:
use strict; use warnings; use XML::Simple; ; use Data::Dumper::Simple; my $struct = XMLin('test.xml'); ; print Dumper($struct); if (defined $struct) { my $result_set = process_data($struct); ; print Dumper($result_set); send($result_set); } #...
Note how debugging lines stand out, but no change to indenting is required. Of course, you'll note that instead of putting the semicolon only in front like PCS, I "sandwich" the statements -- this is necessary, and is in fact easier since I'm used to ending lines with semicolons anyhow.
The additional advantage to this is that debugging statements can be programatically filtered out:
perl -ne 'next if m{^\s*;\s*[^#]}; print $_' debugging.pl > stripped.p +l
Of course, one has to be a little more careful about heredocs:
print <<HEREDOC Some lines go here HEREDOC ; #this would be filtered out if I didn't leave a comment
Thoughts?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perlish Debugging Style
by BrowserUk (Patriarch) on Mar 01, 2006 at 19:20 UTC | |
|
Re: Perlish Debugging Style
by diotalevi (Canon) on Mar 01, 2006 at 19:21 UTC | |
by Anonymous Monk on Mar 01, 2006 at 22:11 UTC | |
by diotalevi (Canon) on Mar 01, 2006 at 22:21 UTC | |
by radiantmatrix (Parson) on Mar 02, 2006 at 17:20 UTC | |
by diotalevi (Canon) on Mar 02, 2006 at 17:33 UTC | |
|
Re: Perlish Debugging Style
by merlyn (Sage) on Mar 02, 2006 at 01:41 UTC | |
by radiantmatrix (Parson) on Mar 02, 2006 at 17:07 UTC | |
|
Re: Perlish Debugging Style
by samizdat (Vicar) on Mar 01, 2006 at 17:23 UTC | |
by Anonymous Monk on Mar 01, 2006 at 18:18 UTC | |
by samizdat (Vicar) on Mar 01, 2006 at 20:16 UTC | |
|
Re: Perlish Debugging Style
by duckyd (Hermit) on Mar 03, 2006 at 00:11 UTC |