Re: hash arrays and other mysteries
Re: hash arrays and other mysteries
- Subject: Re: hash arrays and other mysteries
- From: "Jason W. Bruce" <email@hidden>
- Date: Mon, 22 Oct 2001 11:26:30 +0000
Nothing I've read has convinced me that there is any difference between
"load script" and "import."
Timothy Bates said:
>
Import (would) add new handlers to your script object. Load script add new
>
objects to your script object.
>
>
Basically if what you want is to either break your script into managable
>
chunks without going OO, or just to adorn all of your scripts with a larger
>
set of core abilities (like list and string handling that are needed
>
everywhere), then import would be cool.
>
>
Load script is fantastic for many other things,
>
>
Tim
Tim,
I think this is more a matter of design than functionality. If you're
designing an object-oriented script base, you're supposed to separate your
objects into all-purpose general ones and specific ones, with your specific
objects inheriting the handlers, etc. from the all-purpose general ones. In
your example above, object-oriented design would suggest that you place your
list and string handlers in their own, small generalized script object which
could then be imported/load scripted into your more elaborate and specific
script objects which need those handlers. By separating the general, all
purpose handlers from everything else, you can import/load script them
without bringing in too extra baggage.
In any event, I learned from Scott Norton awhile ago that you can use
load script to load only specific handlers from another script as opposed to
the entire script.
>
Almost. You can't say
>
>
Set parent to string.lib
>
Set parent to array.lib
>
Set parent to graph.lib
>
Set parent to UI.lib
>
Set parent to game.lib
>
>
We humans have 2 parents, but scripts have only 1 and noone has 5
AppleScript doesn't have multiple inheritence, true. But neither does
Smalltalk or Java. From an object-oriented design perspective, multiple
inheritence is questionable.
>
But you can say
>
>
include string.lib
>
include array.lib
>
include graph.lib
>
include UI.lib
>
include game.lib
>
>
So include is good for what it does. Which makes it good. If none ever used
>
it, it would hurt noone. If someone uses it (they would) if is helping
>
>
Tim
You can use load script multiple times also.
Property foo : load script alias ...
Property bar : load script alias ...
Property foobar : load script alias ...
Greg Strange wrote:
>
We were discussing this over on the applemods list. The only problem
>
with this is that if the loadable script changes in the future then the
>
updated handlers won't be available to your script because as a property
>
it will keep static between runs. You would have to open each script
>
and recompile to get the updated handlers.
Greg,
You may know this, but you can use load script either at compile
time or at run time. If you load script at run time, you avoid the static
aspect and can pick up changes in the loaded script.
Tom Wood wrote:
>
AppleScript's 'load script' command adds the procedures or handlers in
>
the targeted script to the script loading it. For example, if scriptOne
>
had three handlers in it for performing mathematical conversion, and
>
scriptTwo needed those handlers to work with some numbers, you can load
>
the handlers using the 'load script' command. This is similar to
>
#include in C++, but different in that you must load the targeted script
>
into a variable, and then refer to that variable (or object) when you
>
need to call one of its handlers. This is actually a powerful concept.
Tom,
Yes, I agree. In my opinion, calling a loaded script's handlers by
targeting variables named in the main script as opposed to merely invoking
the handlers with no name qualification seems to me to be safer and less
prone to name conflicts -- with the same functionality.
Jason Bruce