Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

koschei (147)

koschei
  useperl@dellah.org
http://eh.org/~koschei/

Um. Me. Iain Truskett. Can be found as either Spoon or Koschei around the place, and as Braxiatel in rare circumstances. Um. Cool. Ta.

My perl svn repository [dellah.org] if you want bits of code by me. Also see dellah.org [dellah.org] for most of them in action.

My friends [perl.org], foes [perl.org], fans [perl.org], and freaks [perl.org]. And you can see what my friends are journalling [perl.org].

And everybody's journals [perl.org] (in order of updating).

Journal of koschei (147)

Wednesday October 03, 2001
08:38 PM

The Perl Book Litmus Test

[ #869 ]

From the site "One Minute Perl Book Reviews", which mysteriously vanished at some point since the release of Camel 3:

The Perl Book Litmus Test

Remember, the point of this test is to find bad books and there can only be negative results with this test. A book which passes all the tests put forth here CAN STILL SUCK.

Flip to the index. Look up the following tidbits and answer the questions.

  1. localtime
    Does it state that it returns the number of years since 1900? Does it mention that when used in scalar context it returns a nicely formated date?
  2. srand
    Check how it uses srand(). Does it warn you to call it only once in a given program? (If srand is never mentioned, that's okay)
  3. Number of elements in an array
    Does it say that an array will return its number of elements in scalar context, or does it use $num = $#array + 1;
  4. flock
    Does it discuss and use flock instead of lockfiles? (ie. setting some .lock file instead of using flock().) It's okay if file locking is never discussed at all.
  5. Portable Constants
    When performaing flocking, socket operations or sysopens does it define it use the constants defined by Perl, or do they define their own unportable constants? (It's okay if the book never has to use these constants at all)

All very inspiring. Generally good. I suspect it could do with some refinement though.

  1. uses -w and use strict
    Any program in a book about Perl should be using examples that use warnings and strict. If, for some reason, the code needs to run without strict, it should be clearly noted why (and should probably just have part of the code wrapped in a no strict "refs"; ... use strict "refs"; pair.
  2. Doesn't have redundant code
    As I'm writing this, I'm looking at Programming the Perl DBI and most of the examples end in exit;. This isn't done for any apparent purpose. Like Strunk might have said had he written The Elements of Programming instead of The Elements of Style, "Omit needless code".
  3. Error checking
    The code should be checking for errors. Perl DBI does this generally wonderfully. All calls to functions that may return an error are trapped with "or die" (and when doing transactions it includes a rollback).
  4. In general, the code should not be red flaggable
    MJD has a series of articles about programming red flags: big alerts that something is wrong and that the program should pull into the pit stop. Ideally the programs shouldn't exhibit behaviour like the programs he plays with (well, not the originals that is). I think his articles cover what I want to say quite elegantly.

If all Perl books were like this then the world would be a happier place. Of course, there's still all those existing programs and the people who learn their Perl from them rather than books. Can't win 'em all =)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.