[Melbourne-pm] Perl programming best practices 2011

Michael G Schwern schwern at pobox.com
Sun Jan 9 22:37:52 PST 2011


On 2011.1.10 4:44 PM, Jacinta Richardson wrote:
> My talk for LCA this year is on Perl's current best practices.  It's only 35
> minutes or so long, so I can either cover some topics in depth, or many at a
> high level, or (more likely) a mix of both.  I'm compiling a list of such
> things, and I'm wondering what you'd include?

Assume I like unless otherwise mentioned.


> 	Obvious things to include:
> 
> 		use strict;
> 		use warnings;
> 		use autodie;
> 		use v5.12.0 (or 5.10.1);
> 			say
> 			state
> 		Taint

FWIW I've largely given up on taint.


> 		Perl::Critic

perltidy


> 	For OO:
> 		use Moose (or Mouse or Any::Moose)
> 		if Moose
> 			* maybe MooseX::MultiMethods
> 			* MooseX::Declare

Interesting, but runtime performance is crippled by
MooseX::Method::Signatures.  It does a type check on the invocant every method
call causing a 40x slow down in every method call defined using "method".  It
can barely crank out 10,000 simple method calls on my laptop vs 400,000.
https://gist.github.com/772455

I would instead recommend Method::Signatures, works on functions too, though
I'm biased.


> 		Roles
> 		Type constraints
> 		c3 mro

I don't know how important C3 is once you think in roles.  Multiple
inheritance just goes away.

Method modifiers are worth mentioning for cross cutting concerns and "aspects"
but you can easily write yourself invisible spaghetti code with them.


> 	For experimentation with:
> 		perlbrew    (different perl versions in your home directory)
> 		Local::Lib  (local installs of modules)

Good choices.


> 	Module versioning
> 		ie: use Module 1.2.1;

I would recommend reviewing
http://www.dagolden.com/index.php/369/version-numbers-should-be-boring/
and synthesizing the conclusion.


> 	Testing
> 		Test::More

I'd recommend Test::Most, the most popular test libraries in one module.

Also Test::NoWarnings.


> 	Regular Expressions
> 		\A. \Z
> 		/msi
> 		named captures
> 		escape sequences

Regexp::Common
Alternative delimiters. m{//} instead of m/\/\//
qr{} to compose regular expressions from pieces.

These are old things, but folks still don't use them.


> 	Given/when foreach/when smart matching
> 
> 	Try::Tiny
> 
> Clearly even mentioning all of this in 35 minutes is going to be tough.  Can any
> of you think of anything else that I absolutely *must* mention?

Module::Build and/or Module::Install
Path::Class

perl5i? :)


-- 
Hating the web since 1994.


More information about the Melbourne-pm mailing list