help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practices for loading packages


From: Francesco Potortì
Subject: Re: Best practices for loading packages
Date: Thu, 27 Mar 2014 15:55:24 +0100

>On Thu, Mar 27, 2014 at 12:38 PM, Daniel Kraft <address@hidden> wrote:
>> Hi!
>>
>> I've recently started to appreciate what packages can do to keep code
>> structured in Octave.  Now I'm wondering what the "best practices" for
>> loading packages are.
>>
>> In particular, if I write a function "foo" that uses some package "bar",
>> and then use the function itself from my main program.  What I'm
>> currently doing in the main script is something like this:
>>
>>   clear ("all");
>>   pkg load bar;
>>   ... other things ...
>>   foo ();
>>
>> I. e., I load the package together with a lot of other "initialisation"
>> things right at the beginning of each main program that uses foo.
>> However, in some sense this seems not optimal -- a user of foo need not
>> necessarily know that foo uses package "bar", and also the main program
>> may not need or even want the package to be loaded (except indirectly
>> for using foo).

You can check whether the package is loaded, and load it if it isn't.
You can possibly unload it at the end of the function, if it wasn't loaded.

You can do the above inside a function, but while checking whether a
package is loaded is relatively cheap, loading it is expensive, so if
you call that function many times when the package is not loaded, it
will be slow.

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it



reply via email to

[Prev in Thread] Current Thread [Next in Thread]