Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: package function calling

by polettix (Vicar)
on Jul 12, 2005 at 13:51 UTC ( [id://474277]=note: print w/replies, xml ) Need Help??


in reply to package function calling

If module "MyPackage::MySubPackage" does not export functions by default, you're obliged to use the first version. Moreover, this version wipes away any ambiguity about where the function is coming from, so readability could improve. OTOH, if some_function is used frequently, the full specification could be more a noise than a readability improvement, so you'd probably find some way to import the function name and use the second approach. Just Huffman for programmers.

I would be surprised if there were any performance issues related to the two approaches. But this is a place in which it is quite easy to be surprised.

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

Replies are listed 'Best First'.
Re^2: package function calling
by BarMeister (Beadle) on Jul 12, 2005 at 13:54 UTC
    Ok thanks...I think that covers it...I think I will stick to fully qualified calls.

    Thanks for the advice.

      Before you go and do that, you should probably hear the reasons why it's sometimes (not always), appropriate to import functions into your namespace, or something similar.

      Consider the possibility that down the road, you have issues with MySubPackage in a script, but you still need it for other scripts on the system, so don't want to completely overwrite the module. You create MySubPackage2, which has the same interface as the original MySubPackage, and then you just need to change one line of code in this script:

      #use MyPackage::MySubPackage; use MyPackage::MySubPackage2; some_function();

      If you use fully qualified calls, then you have to go through the script, and find/replace everything, which might be more time consuming. You may also decide that you want to have some logic in your script that dynamically loads the proper 'some_function()' to be used throughout the script, based on other parameters -- in this situation, you want the lines of code that call the function to not worry about what they're actually calling.

      Sometimes, tradeoffs in execution time cuts down on the time and effort to change the code down the road, (is part of the issue with premature optimization, which halley mentioned)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474277]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found