Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: What are Modules

by George_Sherston (Vicar)
on Dec 07, 2001 at 21:08 UTC ( #130236=note: print w/replies, xml ) Need Help??


in reply to What are Modules

I'd just like to add one more answer to the question "what are modules?", namely

"worth taking the time to learn about"

My first six months working with Perl I took the attitude that by the time I'd figured out each new module I could have done the work myself. It was a painful learning process. I now have the zeal of the convert, and my first instinct when I come up with a new problem is to browse CPAN. My advice, FWIW, is, if in doubt assume there's a module that will do it for you.

In particular, if you're working with databases, I'd encourage you to check out DBI.pm, which makes a lot of things a different order of magnitude easier, and even makes some problems go away altogether (here's just one example of what I mean).

Remember it's a J curve... you go a LONG way up for a very little dip at the start. I've tried both ways, and I know which I like better!

George Sherston

Replies are listed 'Best First'.
Re: Re: What are Modules
by dru145 (Friar) on Dec 07, 2001 at 21:31 UTC
    George,

    I agree with you, but I also think it is important for a newbie not to rely too much on modules because even though it will take more time to write your own code, I feel you learn Perl faster this way. This was the case when I started out. People were suggesting modules left and right and I said to myself "How am I going to learn this stuff if all I'm doing is using other people's code?"

    Now that I have a better grasp on Perl, I find myself using CPAN much more. I would suggest to a newbie to try and write the code themselves first and then check out CPAN to see if a module can do something they want better/faster (which is usually the case).

    Hope I don't get flamed for this, but this is the approach that I took.

    -Dru
      No flames, so long as you know you're wrong ;-) just kidding. Seriously though it's dependent on the end user. If they are the curious type and will actually attempt to understand the modules they use then that's good. I just rewrote a script from years ago that I used to select 5 random lines from a file that was atrocious, no scoping, vast assumptions (one of which was causing it to get locked in an infinite loop! Very Bad since it was run by cron), etc. etc. So I got Algorithm::Numerical::Shuffle and the script is now much more stable and trivial. And I really think that it would have been best for me to have used it in the first place long long ago. I would have been more confident in the script (or justifiably so), and spent time on making it work well instead of just making it work. On the other hand I wouldn't have been able to (it would have unnecessary) revisit it and see how very far I'd come ;-).

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"

      It's a balance, really, IMHO. One needs to have an idea how the modules work otherwise one can't use them intelligently. But at the same time one has to let them do the work otherwise there's no point. But my guess is that most beginners err on the side of *not* using modules, and will always find ways to practice their skills by re-inventing a whole load of wheels. I too learnt a fair amount by rolling my own, but I think I would have learnt other things quicker, and been more productive, if I'd made the jump to modules sooner.

      Also, a fab way to learn good programming style is to look at how the modules do it. So instead of learning by rolling one's own, one can learn by getting to grips with the real thing.

      George Sherston

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-06-01 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (12 votes). Check out past polls.

    Notices?