|Welcome to the Monastery|
Namespace Pollutionby Tanalis (Curate)
|on May 05, 2003 at 17:48 UTC||Need Help??|
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 :)