Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Monks,

I'm fairly sure this is something that comes up fairly regularly; however, I think as with Perl, people's tastes with regard to it change fairly regularly as well.

A couple of nodes (fairly) recently have looked at the namespace issue from both sides, from an implementation point of view, but nothing as yet has come up regarding the more theoretical side, which is what I'm interested in here.

My original impression, from reading a number of previous posts here, and from looking through the Camel and Black Book, was that automatically importing subroutines, variables and other symbols from a module to user-code was considered a Bad Thing, something to be avoided.

Having said that, though, I can see that it can, on occasion, be a very useful thing if, for example, importing a module exports a set of common subroutines, or secondary modules, to the user's namespace, saving a user of the module from having to figure out exactly which methods or modules in the suite he actually needs.

Going from one extreme to the other, though, it's also (in my opinion) a very nice thing to be able to call, for example, Date::Calc with a string of simply the subs you actually want to use. For larger, more complex modules, I can't help but think that it makes more sense to import what's needed rather than everything that's available.

I think that my personal preference/solution when I'm both writing and using module code is to have an option of either: if the module is used without arguments, or with an :all flag, a "default" set of subs is exported, but if a list of specific subs is given, only those are imported into the module user's namespace. This, I think, gives maximum flexibility for larger apps, and for future expandability of both the module and for the code using that module.

I'm interested to know what others think of this: is there a set "right or wrong" with regard to something like this? I tend to strive to not export anything I don't specifically need: do people think this the best way to go?

Any comments and opinions are welcome :)

-- Foxcub
A friend is someone who can see straight through you, yet still enjoy the view. (Anon)


In reply to Namespace Pollution by Tanalis

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 rifling through the Monastery: (1)
As of 2024-04-25 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found