moria.org.uk

Sat, 11 Nov 2006

Perl Best Practices

I read this a few weeks ago, and I think it is one of the most useful programming books that I have read in a while. Whereas most programming books are about how to get stuff done, this book is definitely about how to write code that someone else will be able to maintain afterwards. Perl has a reputation of being a fairly compact, fast-to-code language — and the resulting code looking like line noise and being opaque to the next person to look at it. So perhaps perl needs a book like this more than most.

I like how Conway is not afraid to give normative advice. He advocates, rather than defends, a fixed set of standards for things like commenting, indentation, variable naming conventions etc; he gets the balance right between justifying his opinion in favour of certain conventions, and not turning the book into a rehash of what can be endless debates between programmers about the relative merits of, for example, tabs and spaces. Better still, he comes down against the TMTOWTDI principle which seems to run through so much of perl's design and use: he simply dismisses all sorts of syntax features — like unless, and postfix modifiers — pointing out that they add nothing to the expressive power of the language, and do add keyword clutter and increase the risk of maintenance errors and oversights.

The book draws attention to lots of language features and important modules that make code easier and clearer. The Scalar::Util and List::MoreUtils modules, in particular, were a real find for me; many of the modules now standard in perl 5.8 I had not seen written up before, so this was particularly useful.

I couldn't agree with his chapter on regular expressions, though. This part of the book seems to be based on the assumption that regular expressions are hard, nobody understands them at sight, and so they should always be expanded out and commented in verbose and explicit ways. But why should we do this for regexes, but not for algebra? We don't expect people to write out algebraic expressions over multiple lines with extensive embedded comments, the + and - of maths speak for themselves without comments. I see regexes as being a similar compact language for text manipulation, and see no reason to treat them as obscure.

[16:53] | [/books] | #

Colin Phipps.
Archives
January 2007
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
Web Sites
zsync
PrBoom
About Kye
Credits
Blosxom
Powered by
Blogs that link here
[Valid Atom]