Author: Tom Christiansen, brian d foy, Larry Wall & Jon Orwan
Reviewed by: Nikos Vaggalis
The Camel book reaches its 4th Edition and adds to the growing collection of high quality Perl books.
As always when looking for a book, you have to find one that fits your needs, and in those two years we've had something for everyone.
This is a book that covers the core, the foundations, concepts and philosophy of the language
As it covers the core, it has to also talk about all that stuff that gives modern Perl followers the horrors such as not pre-declaring variables, bareword filehandles, plain old minimal OOP. You could very reasonably ask "Why cover all the "archaic" stuff and not just focus on the modern practices and language features?" After all, it is 2012 and Perl has made huge leaps in progress
The authors take the route of preferring to explore all possibilities given by the language, adopting the philosophy that is best to be aware of everything that exists rather than ignore parts of it. Reasons include personal preference, like writing dense, idiomatic and cryptic one-liners for replacing multiple lines of code, aiming for efficiency rather than clarity; or getting up close and personal with legacy code, something that does not sound so improbable when you consider that most shops still use 5.8 in production, let alone 5.12.
Removing parts of the equation to just cover modern Perl, would be as unthinkable as removing the language's "notorious" and uncompromising character
Of course, that does not mean that the book ignores modern practices. It covers them too, as far as the core language is concerned, but it defers them to the point when the time is right, since the authors' intention is to get readers going as soon as possible and incrementally introduce them to the "better" alternatives. This is evident as early as Chapter One:
"You may declare some of your variables, or even force yourself to declare all your variables. But it is your choice. With Perl you're free to do The Right Thing, however you care to define it."
or referring to use strict:
"Since you can add the strict pragma at any time, Perl is also good for evolving small projects into large ones, even when you didn't expect that to happen.Which is usually."
A prime example of adopting modern practices is found on page 161:
"In the old days before use strict, Perl programs would simply access global variables directly. A better way to access globals nowdays is by the our declaration."
Ultimately, that is part of the magic that IS Perl; the saying "use the right tool for the right job" is embedded into the language itself and is transformed into "use the right language feature for the right job". This echoes the Perl motto that was the subtitle of previous editions of this book "There's more than one way to do it" (TMTOWTDI) expressing the principle that Perl doesn't tell the programmer how to program.
When looking at it from an OOP perspective we encounter the same dilemma; should the book cover only Moose, which is years ahead of the build in terms of object-orientation, or cover the non Moose-old school Perl OOP? This again is a matter of personal preference as for the task at hand not all Moose features might be required and instead it might be better to opt for the built-in, straightforward and minimal, OO model. But more importantly, using and extending most OO CPAN modules makes familiarity with the core imperative.
Then another question to be addressed is that, if the book acts as a reference to the language, why not just go through the online perl-docs, or perl-faqs, thus saving a few bucks by not buying it at all?
The answer is that a good in-depth book can't be beaten by a manual, however exceptional that might be.
This volume does not recycle the language's documentation, but instead summons it up contemplatively, pointing at it whenever digging deeper is necessary, like for example directing the reader for more information to the "Data structure cookbook".
In that sense, the 3rd edition is still valid and can be widely used as a reference, but on the other hand a lot has happened in the 12 years since it was published.
In that interval much has changed but Perl has always kept in sync with the roots of the language for backwards compatibility. New features and constructs have been injected, driven especially by the development in Perl6. Essential modules which could be easily be part of the CORE have been added including full support for Unicode 6 and much more.
The book also covers everything up to experimental version 5.16 which may be not targeted at production users but to explorers and adventurers. The biggest additions to the book are in the form of the revamped regex and Unicode chapters, which really do justify the new edition's subtitle of "Unmatched Power for Text Processing and Scripting" indicating how the authors view Perl's biggest strengths.
This edition offers something for everyone; the novice is introduced to the basics, the intermediate acquires new knowledge or re-evaluates that already in possession filling up the gaps, while the advanced one is getting a tour through all the new language features up to 5.16.
But one is for sure; all programmer categories benefit from the Regex and Unicode chapter where Tom Christiansen's expertise is clearly evident.
Parts I and II aim at getting the feet wet by introducing the basics : variables, data types, contexts, operators and precedence, loops, blocks, typeglobs and filehandles, subroutine declarations and Perl's core OOP model with a two-page reference to Moose. I would have liked more Moose, but the authors acknowledge that this subject would easily fill a book on its own.
All the chapters, the early as well as the more advanced ones, explain how the language operates, how this fits with Perl's philosophy, its roots in natural language programming and its diverse view of Computer Science as a technology and culture, which renders it not just a book about programming but offers something more on a higher level. This is about the culture of Perl and the culture of programming.
Part III tackles the advanced stuff. The language's IPC facilities are examined. Again the treatment is loyal to the core but when appropriate, modules that can ease the burden are introduced - such as IPC::Open2 for bidirectional communication or File::Map for shared memory communication.
This chapter contains more involved code examples, necessary for intuitively conveying the information to reader. This is in contrast to most chapters, which contain one-liners and short code snippets with the aim of conveying the point as fast as possible
Then, Chapter 16 shows how a Perl program is compiled and how that process can be affected, while Chapter 17 talks about CLI and the environment, its configuration and all variables affecting Perl's run time operation; very handy information indeed. Chapter 18 covers the debugger and 19 does CPAN, of course.
Chapter 20 Security, marks the start of Part IV and is particularly interesting because it not only shows how Perl goes about the subject but indicates how things work from the OS perspective (this is also holds true for the IPC chapter), especially Unix, as for example the section "accessing commands and files under restricted privileges" demonstrates
Chapter 21 "common practices" goes through tackling frequent day to day tasks and explains when to use one language feature over another. An example of that is:
"use s/// rather than concatenating substrings" or "avoid substs on long strings" or "short-circuits are often faster than the corresponding regexs",
There are also best practices on how to write clear and clean code such as:
"put space before the opening brace of a multline block"
This chapter really is the best representative of Perl's TMTOWTDI principle. but also looks at it from an efficiency perspective.
Chapter 22 explains how to write portable Perl programs so that they are able to run muti-platform, and goes through the intricacies of a variety of OS's such as how Dos/Windows and Unix perceive new lines, or CPU's perceive Endianess.
Chapter 23 is on POD while the next one "Perl as a culture" contains some historical information, the virtues that a Perl programmer possesses, as well as references to forums where you can get help or attend events.
The book concludes with reference material which contains all the keywords and special variables, pragmas and must know modules; formatting with sprintf and printf; as well as paying special tribute to the language's formatting/reporting capabilities which, back in the day, constituted one more reason that Perl was so highly regarded.
After that the complete core function index, together with their explanations and usage, is presented in perdoc style.
Although this edition pretty much covers everything, I have to admit to being disappointed by certain omissions. Material on threading, the languages' TLS model and sync primitives, inter-operating with other languages by means of, for example Inline-C, and on Perl's internals, all of which were present in the 3rd edition, have been removed in this one. For me this pulls it down just a click from perfection. Maybe talking about Perl's internals might not be that important, but threading especially, is a hot subject
Summing up, this is a book that provides a holistic overview of the rich building blocks of the language, giving the programmer a head start on how to exploit them in creative, imaginative and fun ways, something feasible courtesy of the language's revolutionary design
This is a book as unique as the language it talks about. It merits not much shelf time accumulating tons of dust, but a lot of desk time and companionship throughout the Perl programmer's professional career.
|Last Updated ( Tuesday, 09 June 2020 )|