SPUG: Interdependance of package subroutines
Marc M. Adkins
Perl at Doorways.org
Fri May 20 18:46:45 PDT 2005
I am currently using fully qualified function names for a lot of utility
package functions. I like seeing immediately where the function comes
from, it avoids cluttering my local name space, and there's some sense
of increased accuracy in specifying the entire pedigree of the function.
I may be overly fussy about not just importing the symbols. Maybe
because I often use a lot of packages and I'm afraid of some obscure
interaction. Or with my own code, forgetting that I already wrote a
function by that name in a package I use all over the place and having
subtle bugs plague me for weeks.
I never specify something as main::Function(%args), if it's in the
default namespace I just use the unadorned function name.
I don't use the & operator as in your examples, I just invoke the
functions as Package::Function(%args).
My function trees can go three and four deep for subsidiary packages. I
use the tree of classes (namespaces?) to group related software modules
and/or classes. If done properly the names read well, making the
purpose of the function immediately apparent from the name tree.
Most of my code is done in objects. Mostly what I manipulate are things
of the form $object->method(%args). So the long function names I use
are nowhere near on every line. It doesn't seem like a real burden to
type the long names.
Of course, I can touch type. If I was a hunt'n'peck typist I might just
import the blinking symbols and be done with it.
mma
Ken Clarke wrote:
> Hi Folks,
>
> I'm building a library of subroutines, separated into functionally
> grouped packages, for use in CGI scripts and cron jobs. I'm finding that as
> the library grows more and more I want subroutines from one package to be
> available for use in another package, so I'm either calling them by their
> package qualified names [ eg my $result_hashref =
> &MyPackage::my_sub(\%sub_args); ], or if they've been imported into package
> main, directly from there [ eg my $result_hashref =
> &main::my_sub(\%sub_args); ].
>
> I would appreciate hearing your comments on the wisdom of this strategy
> from an architectural standpoint. Testing on various platforms shows that
> everything works as intended but I'm getting an uneasy feeling that there
> may be pitfalls which I am not seeing.
>
> I'd also appreciate recommendations for articles, books etc which
> examine architectural/structural issues of medium to large scale
> applications.
>
> Thanks for your time.
>
>
>>>Ken Clarke
>>>Contract Web Programmer / E-commerce Technologist
>>>www.PerlProgrammer.net
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
> WEB PAGE: http://seattleperl.org/
>
More information about the spug-list
mailing list