I'm going to eat a bit of my own dog food here. Sometimes I'll see a good conversation going on in the Chatter Box that, after a while, I think "This should be a post so more people can benefit and participate." I'm often amazed at how a Perl question that can seem fairly straightforward surprises with varied answers, discussion and some healthy debate. Several people (I'll let them identify themselves and chime in if they wish) taught me a lot more than I expected in the CB today. What follows are thoughts that came out of that conversation as well as a few things that have been on my mind.

"Is it good practice to import only the functions of a module you intend to use?"
I naively asked in the CB if, when and why it would be good practice to specify module functions used in a program. The question came from my use of Math::Matrix last week in a response to an SoPW about multiplying matrices. Somewhat inspired by a book I've been reading on Unix philosophy and my own experience in how I prefer to use graphics programs, I started playing with the code I posted.

For years when I use Adobe Illustrator I hide all the pallets and work in fullscreen mode from the start accessing exactly what I need through key bindings. Only when there is something that has no bindings will I call a pallet or *sigh* the main menu :) . I'll also go as far as deleting entire libraries, colors, brushes, symbols etc. that I know I will not use for the project erring on the side of going overboard since I can always bring something back in.

I'm taking this attitude further by beginning to build my own color, shape and Beziér curve libraries using Cairo as well as a few other Math modules for projects. This way when I open up a new file in Illustrator I have available no more than what I need. A more frugal approach as opposed to starting from a blank document, creating an image, adding and taking away from it only to realize toward the end of the day what a mess I've made. *I go back the next morning, open a new document or copy the first and begin the painful clean up.

I'm discovering I would like to work in a similar way when I program. If I decide to use Module::Name, I would prefer to be able to specify what part(s) of the module I will use adding features as needed.

*Going back to Math::Matrix a few things happened when I naively (more like ignorantly) went back and added 'multiply'.

  1. Math::Matrix is an OO module.
  2. I called a function that didn't actually exist since, again, OO module. Whoops :)
  3. * The script worked fine with the addition. No warnings, failures etc. If I didn't ask about this in the CB and referenced this specific script I would have left it as is.

Unfortunately it seems not every module is designed to facilitate the style of working I'd prefer. There are OO modules, there are modules that export all their functions, modules that export some of their functions and finally modules that call on it's user to import the functions as needed.

Does that mean I won't use modules I'd otherwise find helpful? No, but it would be nice if I had the option to pick and choose what I wanted. I guess if and when it bothers me enough, I'll sit down and write my own modules. Maybe that's not such a bad side effect.

To the monks who gave up their time on a Sunday afternoon — Thank you.



"...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote

In reply to "I Only Wanted a Hammer, Not the Whole Toolbox." by luis.roca

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.