Best Practices
Erin D. Smale
esmale at welshpiper.com
Sun Nov 6 12:59:22 EST 2005
Hello all,
Still plugging away at the tutorials, Dan's book, and the Rev docs. I
also read Richard's Scripting Style Guide (which has a lot of good
points for any language). One thing that I've not yet pinned down is the
conventional wisdom with regard to placement of some items--I know how
some things *can* be done in Rev, but I'm wondering how they *should* be
done. I am hoping that some patient souls on the list can help dispel my
ignorance :-[
* Functions: From what I read, a function can be called by any other
handler in a given script. Is it therefore best to define functions at
the beginning of a script, before any event handlers? If I want to open
a function up to the whole application, should I define it in its own stack?
* Variables: I understand that vars are defined when they're initialised
(except globals, which need to be declared). This upsets my sense of
order somewhat, but I can see the advantages. That said, is it best to
declare variables anyway? Is there any performance impact if I do or
don't? Is it best practise to use the explicitVariables property?
* Variable type: The variable types are easy enough to distinguish, but
I'm still getting used to Transcript, so I want to make sure I'm using
them properly. Can someone check my work here:
(1) Local variable - accessible only within the handler that contains it
(declare within a handler).
on someHandler
local intValue = 5
end someHandler
(2) Script local variable - accessible to all handlers within the script
that contains it (declare within a script, outside any handler).
local intValue
on someHandler
intValue = 5
end someHandler
on someOtherHandler
intValue = intValue * 5
end someOtherHandler
(3) Global variable - accessible to all handlers in the application
(declare in or out of a handler).
global intValue
-- Various handlers in various scripts that manipulate intValue
I apologise for this tedious exercise in confirmation. I'm having fun
with Transcript, and things are working very easily, but I don't have
any background in HyperCard, so I want to make sure that I start out
with good scripting habits for use in the Rev world.
Cheers,
-- Erin
Check out The Chimera RPG:
http://www.welshpiper.com
More information about the use-livecode
mailing list