Book Reviews

The following book reviews are the copyright of their respective authors and no part should be reproduced without the express permission of the author. Publishers and Authors of the books reviewed may reproduce the whole or extracts of a review for their book. To request copyright permission please email webmaster@birmingham.pm.org.

All the reviews herein are the opinions of the reviewer and are not necessarily the views of Birmingham Perl Mongers and its members. If you feel a review or comment has been made in error, please contact webmaster@birmingham.pm.org to rectify the situation.

Perl Books

Static Link: http://birmingham.grango.org/reviews/14

 
Perl Debugged
Title:Perl Debugged
Author(s):Peter Scott & Ed Wright
ISBN:0-201-70054-9
Publisher:Addison Wesley
Reviewer:Barbie

Although this book is primarily aimed at the novice, it is a worthy read for many experienced programmers too. The book doesn't just look at how to debug code, but also what motivates us. In fact much of the book could be attributed to any programming language. Although there are Perl specifics dealt with here, many of the obvious bugs crop up in every language. Perl seems to be better in that it has many helpful modules that can make life a lot easier ... if you let them.

The book tries to impart some of the knowledge that passionate and experienced programmers do more or less without thinking. Leading by examples, the authors show how obvious bugs can disappear, and the troublesome ones get easier to spot. The references cover many good online and hardcopy resources, as well as the command line ones, to further your programming experience. The introduction sets out the thoughts behind writing the book, the essence of which is how to write better Perl. The Perl Debugged title is can be more appropriately put as 'how not to endlessly be debugging your code'. The book's layout and text is very much for a beginner, to try and clarify the topics. I can imagine some more experienced coders might be put off by that, but there are several thoughts here, that even the experience programmer can learn from.

'The Zen of Perl Developing', really tries to explain the mindset of a good programmer. There are many suggestions why we do what we do, and getting in the right frame of mind to code can be a big benefit to spotting the problems before they happen. 'Antibugging', follows on from this with some very easy ways to help yourself; Self-documenting code, indentation and letting the code do the work (no reinventing the wheel). Towards the end of the chapter, there are a list of 35 people, who the authors feel set good examples to other programmers. I was amused to realise I have met 20 of them, and seen lectures by a few others too!

'Perl Pitfalls' looks at some of the common programming errors from not understanding how Perl works. Some stem from syntax errors, but most result in your code doing everything, but what you expected. The reasons are numerous, however the good thing here is that the chapter attempts to not only explain why the code can be misunderstood, but also the simple steps to ensure you avoid the pitfalls in future. The explanations are very well thought out, and highlight why some errors are very easily made.

I personally found 'Tracing Code' interesting, as I have long been using my own module, Devel::DebugPrint, which uses the idea of code tracing as one form of debugging. The chapter takes us further by looking how to use Getopts to use command line options and internal constants to determine whether to switch debugs on.

'Testing Perl Programs' takes a mix of methodologies to look at why program testing is a good idea, and some of the better methods to apply. Some projects employ very thorough and laborious testing procedures, while others use the bare essentials. The chapter explains why there should be testing and at the very least why we should learn from them. Possibly the most useful section of the chapter is about writing your own tests and building up a test suite. Use of Test and Test::Harness are explained in easy steps and are well employed in any regression testing.

'The Perl Debugger', along with the command list in Appendix A, takes a good look at the debugging tool incorporated into Perl itself. Each command and it's arguments are detailed very well with good examples. Debugging tools make following the actual path of code and watching the contents of the symbol table much easier than writing trace code. However, this only works well if you are working in a controlled environment. Unfortunately with many CGI applications, there can be many thousand different variations of parameters to any invocation of your program, especially if using the contents of HTTP headers. However, at least one of the GUI plugins mention at the end of the chapter, ptkdg, can handle that.

The next three chapters, 'Syntax Errors', 'Run-Time Exceptions' & 'Semantical Errors', examine the results of bad or misleading code, how to contain them and understand the error messages that can be reported. These chapters perhaps give the best possible reasons why you should always use the -w flag and the 'use strict' pragma. The authors take the trouble to examine every type of error and help to provide you with a simple set of steps for spotting them. To a large degree, spotting errors is down to commonsense, here the authors show you how to help yourself by reading the clues that Perl can give to you.

'Resource Failure', takes a look at Benchmark, DProf and Memoize. Not all bad coding is about code that fails. In some cases the algorithms we use to solve problems are flawed. Benchmark and DProf can be used to spot potential bottlenecks and give a clue to where your talents for optimisation are better served. However, Memoize looks at what function results can be cached to speed up results. All handy modules to know. Following on from that are a few handy hits and tips for reducing the memory overheads. For example, s///g on a large scalar can be memory hungry, but breaking it into smaller chunks reduce the memory space and increases the speed of you code.

'Perl As A Second Language', is a quick guide for anyone coming to Perl from another language. Drawing comparisons and differences from common commands and functions, the authors highlight some language crossovers that can be potentially hazardous.

'Debugging CGI Programs' doesn't go into too much depth with regards to the different bugs with CGI programs, though does give some good pointers of how to catch some of the potential problems, particularly with taint checking and port listening. It does include some very good reference material, as well as a quick look at the debugger interface, ptkdb, that handles CGI scripts. However, as with command line scripts, most bugs will have been covered in proceeding chapters.

Throughout the book there are 46 bulleted "Perls of Wisdom", which are mostly obvious thoughts, but reinforce much of you should be doing already before running screaming for help. The book hopes to get you to help yourself, by referencing these "perls" you might become a better programmer and reduce the time spent passing the problem to your colleagues.

I would definitely recommend this book to a newcomer to the Perl language, but it is a worthy read for an experience programmer too, especially one who might have got a little too set in their ways. Even if it acts as a gentle reminder to how to spot bugs, it serves it purpose.