Re: Idle Help
Re: Idle Help
- Subject: Re: Idle Help
- From: email@hidden
- Date: Wed, 6 Dec 2000 16:53:31 -0500
On Wed, 06 Dec 2000 10:23:36 -0800, Paul Berkowitz <email@hidden>
>
On 12/6/00 9:56 AM, "Byron Peterson" <email@hidden> wrote:
>
>
> How do I pass variables from the 'run' section to the 'idle' section
>
> without using 'global' or 'property' statements.
>
>
Are using globals or properties against your religion or something? You're
>
not going to get too far in AppleScript without them unless you manage to
>
avoid using handlers at all.
A quote I've been saving for some time, waiting for this topic to reappear.
"Avoid dependencies. Global variables are responsible for most of the evil in
the world. A program infested with globals becomes non-maintainable, buggy, and
a nightmare for all team members. Globals also make reuse all but impossible"
--Jack G. Ganssle, "Break Points", Embedded Systems Programming, vol 13, nr. 11,
Oct 2000.
AppleScript users have more leeway for use of globals, because most scripts are
small. Two variables and three handlers is a reasonable module in most
applications, but a complete script for most of us. Avoiding globals and
grouping handlers and properties into script objects is a way of managing the
complexity of a large script; you just don't need to bother if the whole thing
fits on one screen.
But if you routinely use globals to pass all information around between your
handlers, you might be using globals instead of parameters and return values.
AppleScript's ability to return records and lists allows you to think of
handlers as pure functions, with inputs (parameters) and output (returned
results) and no other interfaces. No side-effects and no back-door dependency
on some other unstated conditions. This is good because when you read the
script line,
set {x, y} to mungleFunction(a,b,c)
you know exactly what pieces of data are involved in this command. If you know
what x, y, a, b, and c are, you know what will happen. The result isn't "It
depends on what's in q and r". And you have to remember that q and r are the
things that change what mungleFunction does.
Your brain works hard enough already. Don't give it more busy-work, remembering
secret interfaces.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden