Updates
Latest Tweet
What's New?
Check out for latest innovation, a computer based training video collection
Like this Page
Learning Perl Objects, References, and Modules Review by raul parolari
"Evolutionary" method to explain Perl Structures, References, Objects
This book attempts something very interesting: not just to describe "how" central aspects of Perl work, but also to understand the process of "how Perl got there". Thus, the book does not serve the "conclusions" right away; it reaches them via a series of experimentations and improvements (in fact, similarly to what is done in other sciences).
To make it interesting (and humorous but realistic at the same time) the book presents a band of "software sailors", who write navigation software. They quickly discover the pleasures of workgroup development; they start reusing software with "eval" (on library files), they then limit unwanted effects with "do", to finally adopt "require" to pull a file only once. Then, after chaos still erupts on name collisions (two different "turn_to_port" routines with the same name, which send one boat into a loop..), the sailors discover "package", and finally, the fleet can proceed with a certain harmony [note: given the structure of the book, "use" will be introduced a lot later, in chapter 12].
This is a very original software lesson; for anyone who reads chapter 2, it will be hard to see the line "package Xyz" and not smile remembering (at least once) the conflicts between Skipper & Gilligan. This is great teaching, as your mind associates a "scenario", not just a "habit", to a programming line.
There are other chapters equally brilliant; more than the "Object" chapters, I liked especially the one on "Subroutine References". It begins explaining how to reference a named subroutine, and it then builds a hash of sub references. Then, it prods us to do the next logical step (with a trick which recurs along the book: "why waste some brain cells to define a name for each subroutine, to only use it to initialize the data structure?"), gently pushing the reader to accept "anonymous" subroutines, code them in the hash structure itself, and enjoy the remarkable simplification of the code that results! The stage is now set to introduce "Callbacks", and then "Closures"; again, with the same method of "one evolution at the time":
a) first a variable is declared to hold the callback, followed by a naked block with a private context and the callback assignment.
b) then the code is simplified with a subroutine encharged to contain the variables on which the closure is done and to return the reference to the anonymous subroutine.
c) last, it shows how the same subroutine can be invoked simultaneously, keeping its own context in every call.
I must say that, after you begin to realize the power of "Closures" (I went back to read "Programming Perl", p 260-262, to fully understand it), you regret that the only example given by the book is so elementary (findFile). Imagine instead, to remain with the sailors theme, a routine which computes a boat trajectory (closing on boat's initial position, velocity, etc), and a main routine instantiating multiple boats and launching them in a race. Multiple automatas in action (with a few lines of code!); this would close the chapter in full glory.
More than once you have the strange feeling that the book was written under a constraint of having less than 200 pages. Examples: it presents a remarkable lesson on Autovivification, but fails to alert against unvoluntary autovivifications (when testing structures for existence).
Or see for, in chapter 2, the section "Packages and Lexicals" whose first line is: "A lexical variable isn't prefixed by the current package because package variables are always global". The statement is not false but it is so awkward at the start a section ("X does not have property Z, because only Y has Z"). Why not to spend a few pages, mentioning the Perl symbol table and on this basis explain concretely the difference between "lexical, global, local"? else, everything remains so abstract.
Still, these are minor defects of an unique remarkable book. The introduction mentions that the material is built on the Stonehenge courses; for all of us without the opportunity to attend them, but able to read, think and experiment, this book is an excellent deal to "see" the Stonehenge people in action.