in reply to Perl as one's first programming language

I don't think I'd recommend Perl as a first language to anyone.

I'm almost convinced by the "say 'Hello world!'" argument, but I think that Perl has too many weird pitfalls for beginners. It makes Lisp and Scheme a lot more appealing, because the beginner learns a simple syntax in a short time, and that's all there is.

Perl as a first language might be best for someone who just wants to get a job done and has no aspirations to be a professional programmer. Such a user might be better off learning only Perl than learning something easier (and less powerful) before moving on to Perl. That is, it's hard to justify wasting time on HappyFunLanguage when you're going to need to learn something like Perl later anyway.

Someone on the path of a professional programmer should learn other languages first in order to learn the various paradigms that Perl supports without mandating (object orientation, functional programming, etc.). This way they can get used to staying inside certain boundaries even when they no longer have them. For example, I think it's good to learn to live with strong encapsulation before one comes to Perl and finds object systems that mostly don't enforce it.

Replies are listed 'Best First'.
Re^2: Perl as one's first programming language
by Jenda (Abbot) on Apr 08, 2008 at 09:22 UTC
    (!= (s(i(m)(p))(l(e)))((e(a s)y)))

    Programs are complex beasts no matter what you use to express them so the simpler do you make one thing, the more complex ends up some other. In this particular case you end up with Lots of Irritating Silly Parenthesis. And searching for that one misplaced character out of thousands exactly the same characters can be very frustrating.

      Programs are complex beasts no matter what you use to express them so the simpler do you make one thing, the more complex ends up some other.

      I don't buy that. I think that Perl makes a lot of things much simpler than they would be in, let's say, C. Memory management, for example. There isn't a complexity debt to be paid. It's not zero sum.

      What I meant by "Perl has too many weird pitfalls for beginners" is not obfuscation but rather things that look good to a beginner but aren't. Examples:

      $x = ~ /regex/; %hash = map { "\L$_", 1 } @array;

      If the poor beginner hasn't learned to Use strict and warnings,

      $hash1 = { a => 1 }; $hash1{b} = 2; # $hash1{a} == 1, right? No?

      I don't think the degree to which a language can be obfuscated should be a concern for beginners. A beginner reads code only from a text book that doesn't obfuscate or from their own programs which they also haven't obfuscated. The problem with Perl for a beginner is that it's possible to write code that looks as if it should work but doesn't because of some obscure historical reason or very common misunderstanding.

      I saw something like this not too long ago:

      foreach (@foo_list) { my $x = "blah $_ blah"; my $foo = $_; while ( something() ) { # more stuff foreach (@bar_list) { other( $_ ); } } more_with( $foo ); }

      I wonder how long the programmer had to debug to figure out that $_ at the end of the loop had changed, and it ought to be saved in $foo. To you and me, "foreach my $foo (@foo_list)" is obvious, but we learned the lessons of $_ a long time ago.

      See also perltrap. (We have a whole section of the documentation for "traps for the unwary"!)

Re^2: Perl as one's first programming language
by Porculus (Hermit) on Apr 08, 2008 at 23:08 UTC
    It makes Lisp and Scheme a lot more appealing, because the beginner learns a simple syntax in a short time, and that's all there is.

    In my experience, people who think Lisp syntax is "simple" are either wizened gurus so lambda-hardened that they even speak in prefix notation, or have never actually tried to use Lisp.

    Contrary to popular myth, Lisp has quite a lot of syntax. It just all looks the same. Sorry, but I don't know how anyone can think that

    (defun foo (x y z) (bar (+ x y z)))

    is easier for a beginner than e.g.

    int foo(int x, int y, int z) { return bar(x + y + z); }

    just because it uses exclusively parentheses and spaces, instead of distinguishing between different concepts by using different characters. You still have to remember where you're supposed to put the parentheses, and because it all looks the same, it's less obvious when you get it wrong. (Remember that we're talking about beginners here.)

    And that's without getting into the bits of Lisp syntax that don't use exclusively parentheses and spaces. Quick, should it be (list 'foo 'bar) or '(list 'foo 'bar), or maybe even `(*list* 'foo 'bar)? Hmm, maybe it should have been ,@(list `foo `bar), or do I mean #A(:list #'foo #'bar)...? Sure, it's obvious to anyone who knows Lisp that most of those examples are nonsensical, but to a beginner it's, well, a bunch of confusing syntax. You know... that thing that Lisp allegedly doesn't have.