|Think about Loose Coupling|
should a module export FUNCTIONS or VARIABLES?by blueflashlight (Pilgrim)
|on Jul 02, 2001 at 18:54 UTC||Need Help??|
blueflashlight has asked for the wisdom of the Perl Monks concerning the following question:
Hi, Monks ...
I recently asked for a review of my first module, and I received some very useful feedback. However, there is a question that I didn't ask that goes to the heart of my module's design, and perhaps future modules that I hope to write.
My module exports several functions; each function takes no arguments, and returns a scalar (or in one function, a three element array.) When I first started designing the module, my thought was to, instead of exporting the various functions, I would instead export a single hash, with the keys being the function names and the values being, obviously, the return of each function.
The reason I did not do that is because several of the functions may take several seconds to complete, and so the act of "use"ing the module in a script made the entire script take that longer amount of time to complete. (Note though, that if all of the functions are exported and used in the script, the script will take the same amount of time.)
Perhaps the answer to my question is "TMTOWTDI", but is there any kind of consensus to whether it is better to have a module export functions (even though the functions take no args) or variables?
thanks for all of the help I've gotten so far, and all of the help I'll be getting in the future! :-) -s-