Re: max script size
Re: max script size
- Subject: Re: max script size
- From: Simon Brown <email@hidden>
- Date: Wed, 26 Mar 2003 20:25:44 +0000
on 20/3/03 0:55, has at email@hidden wrote:
>
Most
>
solid approach I've found is to pass the main script into the
>
subscript, either as an extra parameter to the handlers that use it,
>
or in a separate operation, stuffing it into a property in the
>
subscript where it can be referenced by the subscript's handlers.
Just catching up a few missed days.... this post is like a Eureka moment,
nearly...
I've just done a little test of your concept, as in passing (foo, bar, ME)
as parameters to a subscript. Works luvverly, as a very concise way of
giving access to get (or set) current values of every property/variable of
the main script without using globals.
I am haunted by a feeling that it is somehow a cheat though... I just mean
that while it is fantastically good shorthand for passing all the current
values I thought it would use more memory by passing the whole script rather
than passing an array of relevant variables*.
e.g. (foo, bar, {myProp1,myProp2,myVar1...})
*Hmm.. Just checked a bit more and it seems that passing "Me" is
functionally equivalent to "a reference to Me", i.e. not a copy of the
script but a 4 byte??** reference to the current script (as an object).
** seem to remember from somewhere that object references only use 4 bytes,
but maybe that was on another planet... can U confirm?
I _think_ this is demonstrated by the example below (which I include for my
own understanding and anyone else on the list who is as dense as me):
--------------
script: Sub1 -- (The support script, called from Main)
to anyHandler(x,y,mainscript)
log class of mainscript --> returns <Script>
set anyProp of mainscript to "xyz" -- Change a property of the parent script
return x + y
end anyHandler
--------------
--------------
script: Main
property anyProp: "abc"
set testMod to load script (choose file with prompt "Choose sub1")
set {x,y} to {1,2} -- make up meaningless example parameters
set res to testMod's anyHandler(x,y,Me) --> returns 3, as you'd expect
display dialog anyprop
--> returns "xyz"
-- i.e. value was changed from within the sub-script which referred to
-- this Main script (as an object)
--------------
I take it that the above is an example of what you call "dynamic binding"?
It seems a lot more powerful than the static binding, and also potentially
more dangerous?? The static version doesn't always give access to current
values of properties, only those when it was loaded and doesn't allow the
update of property variable values within the running "Main" script, which
is the beauty of the above "dynamic" example.
Is it ever worth spending the extra typing time to specify individual
properties instead of using "Me"? In some ways it makes the code easier to
understand if I can easily see _why_ I'm passing particular variables as
parameters, but in other ways, just seeing "Me" keeps it compact and
provides a clue that some property of the main script is required for or
_Changed by_ the sub-script.
It seems like such a powerful programming technique that it _MUST_ have some
dangers/drawbacks..... just something to do with the concept of having such
good access to the parent object, the _Main_ routine, at runtime, makes me
think there must be some associated gotchas?
I hope you see where I'm going, and where my understanding is lacking ~:-?
Any comments/opinions can only increase my limited understanding...
-------------
Simon Brown
-------------
PPC 7500 + G3 card + ATAPI card + USB card
MacOS Z-9.1 + Remote Access 4.02/CarbonLib 1.6/AppleScript 1.8.3/Smile 1.8.8
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.