[Mimedefang] Perl Best Practices (was Re: Quickly finding a quarantined message)

Dave O'Neill dmo at roaringpenguin.com
Thu May 10 10:56:03 EDT 2007


On Thu, May 10, 2007 at 03:50:31PM +0200, Jan-Pieter Cornet wrote:
> There's a pretty good recent book out, "Perl Best Practices", published
> by O'Reilly, author is Damian Conway. It's certainly an interesting
> read, although I would not recommend following every "best practice"
> advertised.
> 
> However, as the introduction also says, it's worth thinking about the
> issues presented and how and why you choose to do it in another way.
> It made my coding slightly different. I'd recommend it. (If people
> are interested I can even list the chapters of the book that I
> believe are really good practices, and the ones that I believe are
> to be taken with a grain of salt.)

I second that recommendation.  

On a related note, the Perl::Critic package is worth checking out as
well.  It lets you check your Perl for coding standards, including most
of those described in "Perl Best Practices".  Again, its warnings should
be taken with a grain of salt, and you'll likely find a reason to
disable a number of them, but it does make you think about /why/ you
chose to code something in a particular way.

As an example, here's some sample messages from a 'perlcritic' run
against mimedefang.pl:
   String *may* require interpolation at line 27, column 9.  See page 51 of PBP.  (Severity: 1)
   Useless interpolation of literal string at line 107, column 16.  See page 51 of PBP.  (Severity: 1)
   Double-sigil dereference at line 113, column 17.  See page 228 of PBP.  (Severity: 2)
   Subroutine prototypes used at line 150, column 1.  See page 194 of PBP.  (Severity: 5)
   Subroutine does not end with "return" at line 375, column 1.  See page 197 of PBP.  (Severity: 4)
   Subroutine called with "&" sigil at line 1726, column 29.  See page 175 of PBP.  (Severity: 2)
   Return value of "open" ignored at line 1976, column 5.  Check the return value of "open" for success.  (Severity: 3)
   Magic punctuation variable used at line 2173, column 10.  See page 79 of PBP.  (Severity: 2)
   Cascading if-elsif chain at line 5647, column 2.  See pages 117,118 of PBP.  (Severity: 3)
   Subroutine with high complexity score (33) at line 6410, column 1.  Consider refactoring.  (Severity: 3)

(yes, some of those will get cleaned up, but patches are welcome)

Page references to Perl Best Practices are given for the practices taken
from the book, but each Perl::Critic warning can also be looked up in
the manpage for a longer explanation, and details as to why it's not
considered a good practice.

> 
> This is all getting a bit far away from mimedefang, though...
> 

True, but doing anything reasonably complex with MIMEDefang does require
the ability to program in Perl, so it's still slightly on topic.

Cheers,
Dave
-- 
Dave O'Neill <dmo at roaringpenguin.com>    Roaring Penguin Software Inc.
+1 (613) 231-6599                        http://www.roaringpenguin.com/
For CanIt technical support, please mail: support at roaringpenguin.com



More information about the MIMEDefang mailing list