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.
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.
I believe that CPAN is one of the major (if not the only) things keeping Perl alive and well.
It is a great language, and has been used successfully by many huge companies (Amazon for one), but I think if those companies had to redo it again today, I don't think they would choose Perl again. I think that purely as a language, it has been surpassed.
Having a large, mature 3rd party library is what is hampering the adoption of some of the up and coming languages.
Everyone attacks Perl code for being unreadable but I don't think I've ever come across real world Perl code that I couldn't manage to deal with (eventually). I've seen some bad code and written some bad code and Perl doesn't have exclusivity in either of those areas. ;)
Does someone have a good example of unreadable, real world Perl code? And I don't mean obfuscated Perl contest entries.
When it comes down to it, other people's code is just freakin' unreadable no matter what they write it in. In fact, my own code looks unreadable and unmanagable if I haven't seen it in awhile. Just the nature of the industry.
Maybe Perl is just a high profile target since the internet is full of small (and useful) pieces of Perl code?
Pear only has a handful of modules compared to CPAN, in all fairness.
Jeremy
I love and use Perl. But the grammar is already rich and varied. Throwing incorrect Perl6 code into the mix is going to make Perl5 code even harder to read. I sure hope not too much of this stuff makes it onto CPAN (although I know some of it already has).
No. Here's your main problem:
First, I'm not really a programmer.
I wrote the entire engine.
But it's getting complex and difficult to maintain as it is.
And the performance is not holding up.
So you're admittedly not a very experienced programmer, and you're expecting to have the web logic engine that you built, presumably from scratch, be scalable and modular, without ever refactoring it? In programming, we call the kind of query you just gave a 'silver bullet' problem, and unfortunately, there is none in this case. No one language, or framework, for that matter, is going to fix problems inherent in poor design. That's not to necessarily denigrate your programming skills, but don't expect that rewriting an app that was developed from scratch and is exhibiting growing pains to see great speed and modularity gains by porting it to another language. I've got a good hunch that if you started all over again, still using Perl, and chose your toolset wisely, your app would be more stable, scalable, functional, and modular.
I've worked with a lot of web languages/frameworks, and yes, Ruby would similarly solve the problem, but please don't ever say "real-world use of OO" with regard to Ruby. Rails is what, a year old? Basecamp and 43 Things are the largest sites actually running Rails (the latter being as esoteric as you can get, and pretty low-traffic, at that), and you're not going to see a major player using Ruby at this poing. If I take your meaning of "real-world" correctly, CORBA is more like what you're talking about, though I don't think you necessarily want to mess with that sort of thing right now.
--- What
PERL5 is (relatively) compact. It does what it needs to do. I can quickly write fast and compact programs to do dirty tasks like extracting data from a log file. Moreover, I can easily decipher another person's PERL program.
Attempts to bloat PERL to include every conceivable widget is little more than an ill-advised attempt to morph PERL into a full-blown development language (e.g. C#) for creating million-line programs. Does anyone remember PL/1? It was supposed to be the be-all/end-all language and incorporated so many bells and whistles that few programmers actually learned how the entire language worked.
Remember the wisdom of the ancients: bearded, graying, almost senile UNIX programmers wearing code-bottle-thick eyeglasses. KISS means "Keep It Simple Stupid".
Performance is an issue. So are available packages. My backend is postgresql and I need whatever language I use to have an extremely capable and flexible and mature postgresql DBI.
From the standpoint of integrating a website/database, the database will always be your substantial performance bottleneck, unless your code is utter garbage. PHP, Python, or Ruby are all adequate for this task.
The biggest thing you can do for performance is design a Normalized database, and to make sure there is proper indexing for all the queries you run. If you put adequate research and effort into these areas, you'll see better performance gains than putting any effort into rewriting code.
Mmmm, -funroll-loops
I've been asking myself a lot lately why so many people seem to hate Perl. After spending the last few years going from comfortably familiar to extremely familiar with the syntax and features, I think I have the answer.
When you really get down into the guts of perl, you get to do all kinds of crazy nifty things with XS, AUTOLOAD, regular expressions, etc. Perl's syntax is such that once you're intimately familiar with it, you can be either very expressive or very concise.
A lot of code ends up going the concise route because when you know what you're doing, it's easier to write (less keystrokes). Then perl newbies / passer-byers take a look at it, don't understand it, and freak out and say that perl is crap.
Then perhaps they're threatened because there's a huge community of smart perl programmers that manage to upstage them constantly.
To zoom out on the issue a bit, I'm really sick and tired of this current movement in computer science where so many think that programming should be made into some kind of simple task that anyone can do. Hence you end up with languages like Java that hold your hand really really tight and refuse to let go. Is Grandma writing software really a good thing? Or should we save it for the people who at least have a passing familiarity with computers & networks; hell, someone who might even know a little bit about the basic mechanisms in a typical UNIX kernel?
(I refuse to drive a car built out of legos... I don't care that the technology enabled your three year old to do it... it's a high speed highway, damnit, and my life is on the line!)
Make no mistake - there's still an undergound of brilliant developers that understand their systems inside out and produce amazing, high performance code. Many of them are in the open source community. And we refuse to let go of our power tools. You may use whatever language you like, but expect a well-deserved ass kicking if you get in our face and try to tell us you know better.
So, if you want a language for scripting 9in the sense that most people with little scripting experience think of it), you might want to avoid perl. If you want a language to elegantly encode brilliant ideas in a short space, go for it.
"A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
never using a programming language again due to an argument you had on the internet identifies you as a particular kind of person.
Python is for weenies who want to be told how their source code should be laid out.
Perl is for weenies who want to feel superior because their language can be write-only.
I prefer Perl, myself. The few times I've used Python, I've hated the enforced layout. It seems like it wants to be a verbose LISP without all the parenthesis, but instead turned into a straightjacket.
When I've used Perl, I've felt that I'm in a maze of twisting passages, each of them the same (or *mostly* the same). But it's a better feeling for me, having the Swiss Army knife with six screwdrivers, a garment steamer, compass, knife, knife sharpener, nuclear power cell, and fly swatter. Yeah, it's a mess, but it's a *beautiful* mess.
But, like any cult, it depends on which one you want to join. Me, I joined the one that serves ice-cream on Fridays, because they allow dogs. The decision on which language to go with is almost as arbitrary, and certainly as absurd. Just pick one and code. Or pick both, and code.
Microsoft is to software what Budweiser is to beer.
People who still care about programming languages are wasting their breath.
;-)
Look at the difference between a bad, a good programmer and an excellent programmer. We're talking 1 to 2 to 10 factors in productivity and quality here, easily.
Programming languages? Unless it's a language (or programming paradigm) the programmer doesn't know (in which case it doesn't matter much whether it is Java, C, C++, Perl, Python or ruby) at all, the difference for the same programmer from one to another may exist (depending on how fluent they are), but likely more on the order of 10-20%.
This is much the same like arguing about indentation and whitespace style. None of the common ones is _significantly_ better than the other, and the time spent arguing about them sure ate up any gains they might have ever offered. Pick one and stick to it, amen.
So, the choice of language is almost irrelevant compared to the person (or team) you get to do the job.
For quite some applications, it doesn't even matter whether the interpreter or the compiler is exceptionally fast or produces such code, as long as it gets the job done. (I've seen people tune code for hours, to get it to run 5s faster at a total runtime of 1 minute once per month. While artistically pleasing, it's a waste of time.)
Sure, there's exceptions to this rule. If you want to write a Linux Kernel module, you're essentially forced to write C. Some languages have either special features in the syntax or many libraries available to solve problems in a specific problem field. (Perl really beats C for writing string matching, for example.)
But overall, these don't matter as much as you think they do.
Now, with that said, one exception I'd like to dip into, and why I'm glad that python exists. (Take note I'm a Perl head myself!) Perl allows not one, not two, but several hundreds of ways of doing the same thing. Picking one of the "best" choices to do something is a matter of style, taste and experience. Understanding it is too. So, I'd argue that -good- Perl is slightly beyond the average programmers, because if you had the skills, you'd be at least a good programmer already.
Python/Java, on the other hand, is stricter. (It starts with enforced code formatting and goes from there.) This, to a free-thinker like myself, often feels like an artifical constraint. _I_ want to decide how to do this, damn it! But, if you want to enable average programmers to just get their small hack in quickly and almost cleanly, Python might not be the worst choice, while Perl might rate pretty low.
I still love Perl. And Perl 6 looks like a real improvement, surprisingly both in features as well as in style - that is quite a feat.
End of rant
Well said. I for one am so sick of the "proof by repeated assertion" that python (and ruby) is more readable than perl. Yet nobody ever shows you 2 pieces of code, one in perl and one in python where it is clear that python is significantly more readable.
http://www.perthonline.net
So, did you switch because you never learned to use perl effectively, or because you're such a crappy programmer that you couldn't remember to use a good coding style unless the compiler barfed when you made a mistake? :) Seriously, perl can be complicated, as there's a lot to learn...
;)
Yes, I'm quite familiar with Python. I prefer perl. My code looks good because I know how to program, not because the language forces me to indent. Changing the name of a hash to a dictionary, an array to a list, and making a distinction between read only arrays and read-write arrays does not make a language better. Replacing semicolons with newlines doesn't make a language better. Removing the ability to coerce types when appropriate doesn't make things better (if I want to treat a number as a string, I shouldn't have to make a big deal about it in a scripting language).
Granted, I have less experience with python thatn with perl, and that drives lots of my preference. But the only thing I've found better about python is the method documentation scheme. That's marginally neat. Then again, I comment my code in perl, and it works fine.
Ignoring my rather facetious comment at the beginning, can you actually give me an example of something python does better than perl, other than really large programs (which I don't think python is all that great for, either) or converting otherwise sane people into frothing zealots?
The problem with any programming language and it's once legacy source code writing style kicks in, this is true for any language, include C, C++ or Perl.
h viz-2.4.tar.gz
t ar.gz
The older the language is, the more chance that you find some unmaintainable legacy source code.
The thing with newer language with Python, Ruby,
PHP, Java and some C++ is that these are "recent" language, therefore, the odds of finding a very old legacy system is smaller.
In 10-15 years from now, you will say that Python, Ruby, PHP or Java is so "unreadable",
because they are no more the "flavor du jour"
and new constructs exists instead. Like most people says about cobol, pascal, scheme, lisp source code.
There is a difference between "unreadable" and "encrypted".
The former was not "expecting" to be unreadable, it is just badly written by mistake or use older construct that nowadays are no more used.
The later was made on purpose, which is the difference.
If you want "unreadable" C source code, take a look at Graphviz Dot, no it's not part of IOCCC and was not make to be part of it, but if you ever try to understand this legacy code, good luck!!!
Disclaimer, Graphviz dot is a nice piece of software, but it cries out loud to be heavily refactored.
In fact, the first two layers were refactored, but the core engine is dated back to the 80's with K&R style and variable/function/struct name being less than 5 characters!
http://www.graphviz.org/pub/graphviz/ARCHIVE/grap
If you want "unreadable" Perl source code,
take a look at any source code, which have:
no "use strict;"
no "use vars qw{};"
use heavily "local"
use heavily "map"
no "return" statement --> $r; == return $r;
use heavily complex non-trivial regexp without documenting them.
no documentation or POD.
use some old perl construct.
Take a look at this one,
clc (gzip'ed tarfile)
Counts total lines, noncomment lines, and statements in C/C++ source.
Written by Brad Appleton in 1995. Implemented in perl.
http://www.chris-lott.org/resources/cmetrics/clc.
and kiss Autrijus' ass for saving their language. The project was completely stagnant before he single-handedly wrote an actual Perl6 (pugs) interpreter. Thankfully Autrijus leads by example and inspires people. What a marked change from the drudgery and stupidity of a certain VM project that was on the fast-track to nowhere.