Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Recently a Seeker ran into some trouble with an example script from a popular Perl textbook, and the immediate response from a prominent monk was "Don't reinvent the wheel! Use module X instead!" This surprised me, as I thought learning how the script worked would be a worthy goal.

But the conflict in opinion brings up a larger question: at what level of program detail is it best hand off duties to a black box, i.e., a Perl module? And if a module is used, what sort of effort should one make to understand its innards?

One of the greatest strengths of Perl is the massive CPAN library of modules available. Code reuse really works here and allows me to be Lazy, in the good sense of not wasting time duplicating fine work already out there and Impatient, in the sense that I can write powerful programs quickly.

But at the same time there is a danger of not really learning about the problem I am trying to solve. I might learn just enough to realize that there is a module that can solve part of my problem. After downloading the module, I might skim just enough of the synopsis to cobble together some code. If it works, great! But if not, I am in trouble - I don't know enough of the underlying structure of the problem or the module to figure out if the bug is in my driver program, my interface code, or the module. Worse, if it sorta works, I might be tempted to not to bother trying to figure things out, because, hey, I've got more important things to do than noodle about in the details. This is laziness and impatience at its worst, and can lead to Cargo cult programming.

For instance, if one was to implement a multitasking server there are several possible approaches:

  1. Use Parallel::ForkManager as is
  2. Copy code for a forking server from the Perl Cookbook and modify it to suit the task
  3. Learn about  fork() and  exec() from the Perl and Unix manpages. Implement the server from scratch.
Which would you choose?

-Mark


In reply to Use modules or roll your own? by kvale

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found