Thursday, February 22, 2007

Perl, Minimal and as a Beginning

So here's a post regarding a new book, Minimal Perl by Tim Maher (and a Slashdot review).

This is a cool idea, a way to look at a usable and easy to learn subset of Perl if you already know tools like sed, awk, etc. This is, in fact, a large part of how I learned Perl.

The thoughts that this leads to, and which really interest me, regard using Perl as a First Programming Language. Teaching and learning to program is a topic that interests me and I've watched the parade of programming languages used for this purpose with amusement, joy, and more recently, horror.

We used to have BASIC and Pascal (Blissful Sigh), but then moved to C (Incredulous Gasp!), then to Java (Hesitant, Lesser Gasp). Some schools seem to be using Scheme, an offshoot of LISP (Faint to Unconsciousness).

I believe that I understand the reasons for all of these choices at the time they were made. I get it. But, I'm not convinced that some of them are the best First Programming Language. Java is probably okay and, thank goodness, gets out out of using C. C++ was an improvement over C as well. I believe Java is an improvement over C++.

I'm not sure how I feel about teaching beginning programmers about object oriented programming or LISP-based functional, non-procedural programming.

What I've wondered about is trying to use Perl as a First Programming Language. It could only excel in that role if you leave a lot of parts out and focus on a simple, BASIC-like subset of Perl. But is there still too much inevitable wierdness (the weirdness that I love!) in Perl to make this a bad idea? I've thought about a book, Perl as a First Programming Language, along these lines, but I'm not sure I'm convinced yet.

Here's an important example.

Life with Perl used in simple mode is good up to the point you need to write a counting loop. Here's how to do it in BASIC (sort of) and it's typically one of the first things you learn in BASIC.

FOR I = 1 TO 10

or something like that.

Now, think of what we need to do in Perl.

for ($i = 1; $i <= 10; $i++) {
print "$i\n";

Hm. Well, a Perl aficionado might point out you can do this:

foreach $i (1 .. 10) {
print "$i\n";

I'll keep thinking about it.