Slashdot Mirror


Perl 6 Now by Scott Walters

Joseph Brenner writes "Every now and then, a beginning programmer asks if there's any point in learning to program in Perl 5, when Perl 6 is going to change everything soon. There are a number of answers to that: one is to point out that Perl 6 is still years away, another is to point out that it is promised that Perl 5 code will run under Perl 6 without modification (a module that begins with the traditional "package" statement is Perl 5 code; if it begins with the new "class," then it's Perl 6)." Read on for the rest of Brenner's review of Scott Walters' Programming in Perl 6 style using Perl 5, a book which answers that question a whole different way. Perl 6 Now author Scott Walters pages 379 publisher Apress rating 7 reviewer Joseph Brenner ISBN 1590593952 summary Programming in Perl 6 style using Perl 5

Scott Walters here pursues what might be thought of as the third answer: you can learn Perl 6 now and immediately begin writing programs in a "Perl6ish" sort of way, using appropriate CPAN modules that have been used to implement approximations of Perl 6 behavior: Perl6::Variables, Perl6::Export, Perl6::Contexts, autobox, Perl6::Classes, Switch, and so on.

There are many caveats about using these tricks in production code, however, and Scott Walters doesn't shy away from warning you about them (e.g. p.43 "Source filters are dangerous" where he discusses their increased start-up overhead and potential bugginess -- though he doesn't mention my own peeve which is that they're very confusing when you try and use the Perl debugger).

So possibly the book is not really quite so well suited to an actual beginner-- who probably should not be told about "use Switch 'Perl6'", but the device of spending the early stages of the book directed toward a beginning audience makes it a very useful review for people like myself who have been reading the Apocalypses, but don't remember every detail.

And on the other hand, the book includes some prominent early warnings about common gotchas that beginning programmers seem to be prone to -- e.g. using dynamically defined variables instead of just using hashes.

The standards for writing English in the Perl world are pretty high -- the core members of the Perl community have always cared a lot about clear writing, and it's arguably the world's best documented language (critics will no doubt add that it needs to be). Unfortunately, I can't say that Perl 6 Now quite lives up to this standard. This is a book that was written in a hurry, and it shows: hasty sentences and minor organizational problems abound (e.g. one or two items seem to be discussed in the wrong place; there are an awful lot of explicit forward references, and yet there's at least one place where something was used in an example before being discussed a few dozen pages later). But then in Scott Walters defense, this is certainly a book that needed to be written in a hurry, because its subject matter is such a moving target.

And where the book really shines is in its code examples: short, clear and to the point; the author repeatedly shows how something can be done in Perl 5 code and how it's expected to work in Perl 6. These examples are always clearly labeled "Perl 5" or "Perl 6" in the comments, so that the two can't be confused.

The subjects of some of the examples are pretty cool: e.g. he talks about using PDL ("Perl Data Language") to crunch audio data in MOD format, which I was completely unfamiliar with. A *.mod file essentially contains the "sheet music" for multiple parts (really, MIDI) plus sound samples that specify how notes will sound for each voice. This is discussed in Chapter 7, which is also the free sample chapter. I also liked random walking Arizona's highways as an example of Graph navigation (Chapter 8, p 159), and I appreciate the fact that he downplays inheritance in favor of delegation in his discussion of objects (Chapter 14, p. 262).

All in all, this book is a fun read for the Perl fanatic.

(Note: the title Perl 6 Now bears a strong resemblance to an emacs package I've been working on called perlnow.el, but there is no relation.)

You can purchase Programming in Perl 6 style using Perl 5 from bn.com; it's also available in eBook format (password protected PDF, using your email as password) for $15. Source code and and a sample chapter are available online: Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

11 of 366 comments (clear)

  1. Re:It's a php/perl post! by Black+Perl · · Score: 3, Informative

    Where are the Ruby on Rails people? I expected 100 of them to speak up before the traditional "FRIST PSOT!!!"

    Well, for one, perl now has a nice framework similar to Rails called Catalyst (http://catalyst.perl.org/). It's a lot closer to Rails than a lot of other languages' attempts to clone Rails. And yet the Catalyst dev team have specifically chosen to diverge from Rails in certain areas, trading a bit of simplicity for complete flexibility, avoiding some limitations you could run into in Rails.

    --
    bp
  2. Re:PHP5! by Spy+der+Mann · · Score: 2, Informative

    Does PHP have the equivalent of CPAN?

    Yes, it's called PEAR: The PHP Extension and Application Repository.

  3. Re:Pointless Perl6 by A+beautiful+mind · · Score: 3, Informative

    Please do not moderate parent up, because it's just a guess at most.

    Perl6 is actually built from user feedback, for the first time.

    From wikipedia: Larry Wall, the creator of Perl, has called Perl 6 "the community's rewrite of Perl", because he has based the changes largely on 361 "requests for comments" submitted by the Perl community in 2000. He is outlining these changes in a series of long essays, called Apocalypses, which are numbered to correspond to chapters in Programming Perl ("The Camel Book"). The current, unfinalized, specification of Perl 6 is encapsulated in design documents called Synopses, which are numbered to correspond to Apocalyses.

    Parent is NOT insightful.

    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
  4. Re:Attracting new users, competing with Python? by Coryoth · · Score: 3, Informative

    Perl6 has the advantage of starting from the beginning, taking all that was learned from the evolutionary development that lead to Perl5, as well as the lessons learned from other languages like Python and Ruby. Honestly, read through the design commentary for Perl6 by Larry Wall. There are a lot of good ideas there, and Perl6 promises to be a much cleaner, more consistent and more elegnt language than Perl5 - that is, it has learned what was good in Perl5 and thrown away the (vast amounts) of cruft. Looking at what they're proposing, if it actually works as promised then I do think it will compete well with Python - and I'm a Python person myself*. Honestly, read a little of what Perl6 has to offer before you dismiss it out of hand. It looks like it will be a very nice language indeed.

    Jedidiah.

    * One of the things I like about Python is that they're willing to deprecate and then *remove* features to help combat cruft.

  5. Re:Are people still using PERL? by Lost+Found · · Score: 2, Informative

    Actually, mod_perl performance beats the pants off everything but raw C modules when doing Apache web applications.

  6. Re:Are people still using PERL? by hahafaha · · Score: 3, Informative
    This is very far from the truth. Perl is still used heavily for many things ranging from games to CGI.
    I thought it was a passe fad like Java.

    The same goes for Java.
    Seriously, doesn't it remain too slow in execution spped ... and the quick knock off jobs you can do with it are better done in bash and awk?

    Bash and Awk are not powerful enough to do some of the jobs Perl can do. And Perl is only slow with some things, and in comparison to really serious languages like C/C++.
  7. Perl6 is closer than you think by jjn1056 · · Score: 4, Informative

    check out "http://pugscode.org/"

    for a working perl6 compiler. Yeah, it is not yet feature complete, but progress is very rapid.

    Perl6 is really amazing. It removes most of the worst parts of perl5 and make things even easier on the programmer. If you do an research at all you can find that.

    Some people are even starting to port important CPAN modules to perl6 and discovering how much a pleasure it is to use.

    see http://www.perl.com/pub/a/2005/07/28/test_builder_ p6.html

    as an example of that.

    btw, check out the example code. for all of you who think perl5 looks like static on a tv screen, you will be pleasantly surprised I think.

    peace

    --
    Peace, or Not?
  8. Re:Attracting new users, competing with Python? by belg4mit · · Score: 2, Informative

    It's a false perception. 5.6 was leaps and bounds above 5.0.5, and 5.8 is a quite a stride past 5.6.
    Not everyone buys into 1, 2, 3, 95, 98, 2000 type
    numbering schemes :-P There was even a proposal that
    perl 6 should be the last major number and the versioning should approach 2pi

    --
    Were that I say, pancakes?
  9. Re:Show some "unreadable" Perl code or shut up by Anonymous Coward · · Score: 1, Informative

    Well, the think about Perl is it's just a little too hairy. Too much "noise". And some things are weird. For instance, there are two sets of operators, one for numbers, one for strings. What a pain! And you have to remember the difference between lists, arrays, and arrayrefs. Here's a little example. Yes, I know they are both "readable", but the Perl code is slightly less readable and slightly less easy to type. The Ruby code just flows from your fingers while the Perl code requires typing too much punctuations and remembering to load Data::Dumper, and other little annoyances. If you don't "see" the difference, then by all means, stick with Perl. I admit, it's subtle, but I can't imagine going back to Perl after using Ruby.

    Perl:

      my @customers = Customer->find_all;
      my @sorted_customers = sort { $a->name cmp $b->name } @list;
      for my $c (@sorted_customers) {
        print "Customer #@{[$c->id]} has @{[scalar @{$c->acct_a_list}]} A accounts "
              . "and @{[scalar @{$c->acct_b_list}]}\n";
      }
      # debugging
      #use Data::Dumper;
      #print Dumper(\@customers);

    Ruby:

      customers = Customer.find_all
      customers.sort_by { |c| c.name }.each { |c|
        puts "Customer #{c.id} has #{c.acct_a_list.length} A accounts " \
              "and #{c.acct_b_list.length} B accounts"
      }
      # debugging
      #p customers

  10. Re:about package statement by chromatic · · Score: 2, Informative

    Then run it with Ponie or your existing Perl 5 compiler, or add package main; at the start if you change your hash-bang line to /usr/bin/perl6 instead of /usr/bin/perl.

    The point of the check is to re-use modules, not standalone scripts, so that you can migrate your code to Perl 6 gradually.

  11. Re:Why is Perl so hated? by chromatic · · Score: 2, Informative
    count($arr) is better than $#arr because it's bleeding obvious what count($arr) does.

    Not to me. count($arr) should always return 1, unless you meant count( @arr ) and want to break the consistency of list flattening everywhere else in the language. Of course, in Perl 6 you can say @arr.elements to get the number of elements in the array (though "elements" is a long method name, so there may be an alternate at some point if there's a good, clear, shorter synonym) or evaluate the array in numification context with +@arr.

    And if you didn't know what $#arr does, there's no way to index that sort of thing in manual.

    Sure it is! See perlvar, one of the oldest documentation pages. (If you never even knew of that page, it's well worth your time to browse the perltoc manpage.)