http://www.perlmonks.org?node_id=187082


in reply to Re: Re: Learning Perl as a First (programming) language
in thread Learning Perl as a First (programming) language

I'm not impressed by your example of doing little things. Even in C (which I don't recommend as a first language), it's easy to do - in fact, it translates almost token for token. It's like saying a Ferrari is a good car to learn driving with because it's easy to turn on the headlights.

You say that Java isn't your idea of a lightweight language. I don't disagree with that, but hopefully you aren't suggesting that Perl is. Perl is far from being lightweight language, in all aspects. It has a syntax hardly anyone, including wizards with more than five years of experience, can fully remember, and it has a very wide range of primitives. I doubt there's a language with a significant user base out there that has such a complex function to open a file. It was only yesterday that on perlmonks people were confused about 1-arg open.

Abigail

Replies are listed 'Best First'.
Re: Re: Learning Perl as a First (programming) language
by talexb (Chancellor) on Aug 02, 2002 at 13:54 UTC
    Since you asked, here's the equivalent in C (for those that aren't familiar -- I'm sure you are):
    #include <stdio.h> int main(void) { int i; for ( i = 0; i < 10; i++ ) { printf ( "%d", i ); } }
    The equivalent in Perl is
    for ( $i = 0; $i < 10; $i++ ) { print $i; }
    No variable declarations, a friendlier print statement, and no mysterious 'cargo-cult' include thingy.

    Don't get me wrong -- I have programmed in C since the early 80's and I love the language. But Perl takes care of lots of the underlying stuff (how many times did I write fopen(), fread() and fclose() statements I wonder). That's why I think Perl is a better choice than C.

    Perl can be a heavyweight language, but it can also be lightweight. To use the car analogy, C is a bit like the British Triumph, a little finicky, but piles of power and cornering. Pascal is a bit like a Pinto or a CV5 stuck in second gear. Perl is like a Porsche or a Lexus, nimble yet powerful.

    --t. alex

    "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
    --Michael Flanders and Donald Swann

      Well, you are forgetting a my $i if you want to have equivalent code. I maintain the code is nearly identical - there's a few lines more in C, which look a lot for such a short program, but it wasn't linear in the size of the Perl program. Had you have had 100 of such loops, you'd have had the same amount of extra lines.

      I never claimed that C would have been a better choice than Perl. Instead, I said that I didn't consider C a good first language either. IMO there's only one reason to learn C before learning Perl and that's because there's so much of C in Perl. It makes you a better Perl programmer.

      Abigail

          Well, you are forgetting a my $i if you want to have equivalent code.
        No, :) I purposefully left it out, in order to demonstrate the point that Perl will autovivify a variable for you, while C will just throw an error. I also purposefully did not use strict or include the she-bang line.

        --t. alex

        "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
        --Michael Flanders and Donald Swann

      Perl is like a Porsche or a Lexus, nimble yet powerful.

      I rather think Perl is more like a little Z3 that'll turn into a cement mixer, eigtheen wheeler, station wagon (complete with wood panel sides), tow truck, fire engine, or lear jet with the push of a button.

      Ok. . . with the push of many buttons in exactly the right order. . . or close to the right order anyway.

      -sauoq
      "My two cents aren't worth a dime.";