The same speed benefit is conferred at the top-level by way of my
To be clear, “That Script Object Kludge” is just the common title for this “technique”. It’s the extra referencing that provides the speed-up:
item N of listVar of someObj -- O(1)
instead of:
item N of listVar -- O(n)
And since the reference can only point to a script object property, that means either a top-level property or a property of a script object that’s local to the handler. The latter is a couple more lines of code but avoids creating coupling between handler and global state, so from a software design perspective:
to foo()
script kludgeObj
property p : {...}
end script
...
-- do stuff to `p of kludgeObj` here
end foo
is preferable to:
property kludgeProp : {...}
to foo()
...
-- do stuff to `kludgeProp of me` here
end foo
kludgeObj
and me
are both script objects; the difference is purely in the objects’ scopes. With the local script object, you know at a glance that only foo
uses its property, not any other handler; whereas with a global script object you have to think about what other handlers might interact with that property, so it’s harder for humans to reason about. (The machine doesn’t care either way, of course.)
Like I say, AS is just ghastly crap all the way down, making what should be genuinely simple to learn look simple on the surface but an absolute obfuscated insanely complicated mess underneath. We use AS not cos it’s the best tool for the job but the de facto only tool available.†
–
† Not 100% true: Python 3 appscript, SwiftAutomation, nodeautomation are all fully capable of replacing AS from a technical standpoint, giving still-awful but less-awful-than-AS languages the same access to “AppleScriptable” apps that AS has always enjoyed. But there’s a reason I stopped providing [free] support for those alternatives years ago; so, as I say, AS is the only real option in practice unless you’re extremely brave/foolhardy/or have a support contract with me for whatever solution I built for you that uses it.