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?
In reply to Perlish Debugging Style by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |