Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Re: Re: Perldoc, the tutorial

by Juerd (Abbot)
on Jun 04, 2002 at 20:39 UTC ( [id://171629]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Perldoc, the tutorial
in thread Perldoc, the tutorial

The tutorial you describe, the one on http://www.sthomas.net/roberts-perl-tutorial.htm, covers a lot of subjects, which is good. It warns about some common mistakes, which is also good. But even by skimming over it, I found a lot of mistakes. I'll list some of them below.

  • Subs are at the bottom. This is bad habit, as this will make your programs share all file scoped lexicals. Some people know the dangers and still put subs at the bottom, which is their own problem. Tutorials should not have subs at the bottom, but near the top.
  • Strict is mentioned somewhere near the end. This is awful. Imho, all examples in a tutorial should be strict-compliant, as you will only disappoint people by not making sure they are.
  • ⊂ is used. This is very, very bad, as this implicitly passes @_. If you know what it does, go ahead and use it. Do not use it by default. This is not explained in the tutorial. It even says:
    Subroutines are usually called by prefixing their name with an ampersand, that is one of these -- & , like so &print_results; . It used to be cool to omit the & prefix but all perl hackers are now encouraged to use it to avoid ambiguity. Ambiguity can hurt you if you don't avoid it.
    WHAT?! Please, learn some Perl 5 before writing a Perl 5 tutorial, Robert Pepper.
  • The list of comparison operators does not include <=> and cmp. The list is incomplete.
  • chop is being used. It is bad, and its use should not ever be encouraged. chomp is mentioned, but chop comes first, which is the wrong order, imho.
  • C-style for is being used where iterating over the array elements themselves would be a lot better. The author knows this, but uses C-style for nevertheless. If he really wanted to show how it works, his explanation should be more detailed, and a non-array should be used.
  • "$_" is used where $_ is enough.
  • ^$ are said to match begin and end of the string, while they match begin and end of the line, and their semantics can be changed with /m.
  • If you want to negate the entire regex change =~ to !~ (Remember ! means 'not equal to'.)
    That is not true. != and ne mean 'not equal to'. ! only negates in a boolean fashion. It is the "not" operator in short form.
  • As alternative delimiters, #s are being used. This is a bad idea, because this way, you will have problems when using /x with comments, and it looks odd.
  • \1 is used instead of $1 in the RHS of substitutions. This works, but should be considered a bad feature. perlre covers this. Has the author never read the documentation?
  • srand is being used. Do not use srand, unless you REALLY know what you are doing. This is covered in perlfunc and should be common knowledge. Perl 5 programs should not use srand. Is this an upgraded Perl 4 tutorial?
  • Filehandles are not explicitly closed. This is a problem. flock is not discussed. This is a big problem.
  • $^I is being used _before_ -i is mentioned. Bad.
  • The heredoc example has no quotes around the ending keyword. This is not wrong, just bad style.
  • system's multiple-argument form is not discussed. People will get bitten by variable interpolation sooner or later.
  • A module is created without a package. Exporter isn't even mentioned. I would not call this a module. A function library, perhaps. Reading perlmod was too hard, I guess.
  • CPAN is mentioned, but only twice and no examples of available modules are given. CPAN is one of the most important features Perl offers.
  • $MAIN::name is used. The default package is not MAIN. It is main. This should be known.

This is just a few of all mistakes/errors, as I only skimmed the surface. I think it wouldn't be hard to find more.

I will try contacting the author and send him a link to this rant. update: netcat.co.uk does not exist. I was unable to contact the author.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Perldoc, the tutorial
by erikharrison (Deacon) on Jun 04, 2002 at 21:25 UTC

    ++Juerd

    I probably shouldn't have mentioned this tutorial, without going back and reading over it using my newfound understanding of the language. The thing that was appealing to me about the tutorial was that it compiled (which is not true of a signifigant number of online tutorials) and his writing style was easily understood. It is worth noting that several of your complaints could be (emphasis on the could) construed as style arguments. But to say that is as much to retro justify having posted the link in the first place, which I shouldn't be doing :-).

    An unfortunate fact is that it may be the best online tutorial that is widely available. In fact, I came across via a link from http://perl.com so in my youthful innocence I assumed it was accurate.

    Oh, well.

    Cheers,
    Erik

    Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

      I probably shouldn't have mentioned this tutorial,

      Do not argue that way. It gave me the opportunity to rant (which I like to do *grin*) and warn others, and it gave you some insight into your own progression.

      The tutorial isn't all bad. If some things are fixed, some added, some removed this would be a great tutorial. Unfortunately, the author could not be reached.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

Re: Re: Re: Re: Re: Perldoc, the tutorial
by Anonymous Monk on Jun 07, 2002 at 07:59 UTC
    Not all of the things you point out are as grievious as you make them out to be.
    • Not quoting a heredoc terminator is hardly bad style.
    • Strict isn't mentioned early enough which is a valid complaint, but even Learning Perl 2nd ed didn't have and entry for strict in the index, though it does actually talk about it for a few paragraphs on page 99. Did you used to recommend this book? This tutorial does a better job covering strict than the 2nd ed Llama which came out about the same time.
    • Subs at the bottom is more of a religious issue. Yes the file scoped lexicals are then shared with the subs but I've never once seen this cause a real-world problem with the code and many coders, of varying skill levels, I've worked with.
    • Using # as a delimiter is fine, in the right context. The rule is simple: pick a delimiter that makes the pattern easier to specify, and # does that just fine for many.
    • srand was not automatically called in versions prior to 5.004, and 5.004 only initially came out the same year this tutorial was first written (1997 according to copywrite notice).
    • He did show the C for loop style, for with range, and foreach over an array discussing implicit use of $_. I really don't grasp your complaint on this point.
    I am not saying your points are wrong, and I'm not saying the tutorial is all good and correct, just that this particular tutorial isn't as bad as it has been made out to be. Yes Robert's tutorial is far out of date (last update 1999 it appears), and some content was out of date when it was written. It was still, and maybe still is, one of the better such tutorials out there. I haven't read the new perlintro in 5.8.0RC1 yet.

      * Not quoting a heredoc terminator is hardly bad style.

      It implies double quotes, which newbies often don't expect. How many questions have you seen about why code doesn't work that look like this (warns because of @bar):

      print FOO <<END_OF_MAIL; To: foo@bar.com ... END_OF_MAIL
      If you use the terminators unquoted now, better get used to quotes before Perl 6 arrives. Quotes will no longer be optional, according to one of the Apocalypses.

      # Strict isn't mentioned early enough which is a valid complaint, but even Learning Perl 2nd ed didn't have and entry for strict in the index, though it does actually talk about it for a few paragraphs on page 99. Did you used to recommend this book?

      No, I do not recommend Learning Perl. I read it after learning the language, and was disappointed. Didn't even finish reading. It's a nice book for people who want Perl as a scripting language to automate some common tasks, but maybe I'm too much involed with larger projects to judge. I have recently read some Java books, and although I hate the language, I must admit the learning part is better, partly because some style is enforced.
      strict should imho be default in every example, at least use my a lot. Do not let beginners drown first only to tell swimming was the better option. Perl tutorials and books often get this wrong. Good programming habits seem to be unimportant, and I disagree. That you can do without declaring variables, doesn't mean you shouldn't. I'm glad strict will be default in Perl 6 modules.

      # Subs at the bottom is more of a religious issue.

      It is only religious to those who put them at the bottom. Most of the top-subbers are rational.

      Yes the file scoped lexicals are then shared with the subs but I've never once seen this cause a real-world problem with the code and many coders, of varying skill levels, I've worked with.

      Either you don't combine your "main" code with subs, or you haven't done large projects. Another possibility is that your main code itself is in a sub.

      # Using # as a delimiter is fine, in the right context.

      I did not say it was bad. It's just confusing. Tutorials are for beginners, not for people who already know how to make choices.

      # srand was not automatically called in versions prior to 5.004, and 5.004 only initially came out the same year this tutorial was first written (1997 according to copywrite notice).

      My mistake. I thought automatic srand was introduced together with 5.000 itself.

      * He did show the C for loop style, for with range, and foreach over an array discussing implicit use of $_. I really don't grasp your complaint on this point.

      The order is, in my opinion, wrong. First comes the C-style loop, then comes a foreach loop that still uses an array index and then there is our beloved foreach loop that uses the actual array values. It should be the other way around: first loop over the array itself, then show how one can use the indexes and then discuss the advanced topic of C-style loops. -style loops should be accompanied by a while-equivalent, as it's strange to assume newbies will understand what EXPR, EXPR and EXPR are.

      It was still, and maybe still is, one of the better such tutorials out there.

      That is the nauseating part. This being one of the better ones means that most tutorials are even worse. But as I said, this tutorial could very well be a good one if some changes were made. Unfortunately, the author could not be reached at the address near the end of the tutorial.

      I haven't read the new perlintro in 5.8.0RC1 yet.

      It's a good introduction, but not really a tutorial. I would recommend beginners to read it before they read a tutorial or book.

      - Yes, I reinvent wheels.
      
      - Spam: Visit eurotraQ.
      

        Didn't even finish reading. It's a nice book for people who want Perl as a scripting language to automate some common tasks, but maybe I'm too much involed with larger projects to judge.

        That's a good point. Do you think Robert's tutorial was ever intended as anything more than that? I'm not saying it is as good as the 2nd llama, but it doesn't fall that far below it, and it does rank a good ways above learning Perl from Matts scripts, and it is free. Yet the llama is "nice" and Robert's tutorial is nauseating. A few points of comparison between 2nd llama your list of "mistakes".

        • llama also puts subs at the bottom.
        • llama also doesn't quote heredoc end tokens
        • llama also shows using # as re delimiter, and even calls it their favorite.
        • llama also shows C style for loop before foreach, and doesn't mention that for and foreach are synonyms.
        • llama also mentions strict late with less coverage
        • llama also says ^$ match beginning and end of strings (not lines)

        But I suspect neither you nor screamer ever used the word nauseating in describing the 2nd llama.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://171629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found