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: Daniel Kraft
Subject: Re: Best practices for loading packages
Date: Fri, 28 Mar 2014 07:02:55 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

Hi!

On 2014-03-27 15:55, Francesco Potortì wrote:
>> On Thu, Mar 27, 2014 at 12:38 PM, Daniel Kraft <address@hidden> wrote:
>>> 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.

Yes, something like this was what I thought about -- but possibly
implemented already in Octave, like just calling "pkg load" with some
option to indicate that the package should be loaded only for the local
scope.

I already feared that loading/unloading would be expensive, and am
satified with just loading the package at the beginning.  I just wanted
to make sure I didn't miss something. :)

As a feature request, I think it would be cool to have something like
"load for local scope" if it could be implemented efficiently ... but
for me it is also not very important, just "nice to have".

Yours,
Daniel

-- 
http://www.domob.eu/
OpenPGP: 901C 5216 0537 1D2A F071  5A0E 4D94 6EED 04F7 CF52
Namecoin: id/domob -> https://nameid.org/?name=domob
--
Done:  Arc-Bar-Cav-Hea-Kni-Ran-Rog-Sam-Tou-Val-Wiz
To go: Mon-Pri

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

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