The long answer on when to use a function vs command
Jeanne A. E. DeVoto
revolution at jaedworks.com
Wed Mar 15 14:21:11 EST 2006
At 10:13 AM -0500 3/15/2006, Thomas McGrath III wrote:
>I am curious as to any other unique aspects that could affect a
>decision on which to use in different situations.
>Functions are normally used with a 'put' or 'get' -- Is this true?
>Commands are normally used alone (with/without a parameter) but not
>usually with a get or put -- Is this true?
Not necessarily. I think an easier way to think of how functions are
used is to consider that a function can be part of an expression,
while a command is more of a thing unto itself. Consider:
put myFunction(this,that,theotherThing) into field "Result"
if myFunction(this,that) + 1 > 25 then beep
wait until myFunction(that,theOtherThing) is true
In all these cases, the function call substitutes for a value (a
number or string), and the line it's on uses that value. This is not
possible with a command.
>Is one more friendly with a lot of parameters? -- enough params that
>you would need a switch/case
Not really. You use the parameters in the same way, once you're in
the custom handler.
>If you have a function to get some info on an object like:
>put getObjInfo("objName") into field "Info"
(I'd probably name it objectInfo, not getObjectInfo. No functional
need, but I think it reads better that way. "getObjectInfo" reads
like a command.)
>Would you use a command to set that info like: -- or should this be
>a function too? -- (ignore the cust prop aspect for now)
Think about it like this: what's the routine's main purpose in life?
Is it to do something, or to return a value? It sounds like setting
the object info would mainly exist to do something - set a property,
perhaps - so it ought to be a command.
jeanne a. e. devoto ~ revolution at jaedworks.com
More information about the Use-livecode