THE number of...

J. Landman Gay jacque at hyperactivesw.com
Mon Jan 14 02:20:01 EST 2002


erik hansen wrote:

> put tot(it,l) into tot
> shorter
> put (the number of lines in it) into tot
> clearer
> 
> only thing is, nobody else does this.
> maybe clearer is better than shorter?

Depends. In this case, the clearer method takes less time to execute
too, so it's probably better. MC has to get the number of lines (or
items, or whatever) no matter which method you use, but it takes extra
time to load up the custom function's parameters, send it, and get the
results back. So by moving a single native MC statement to a custom
function, execution time is increased. Leaving the function inside the
handler is marginally faster. (MC is so fast in general though that the
difference in this case would be miniscule.)

In other cases, calling out to a function might be better, especially if
the function is long or complex, or if it does something that several
different handlers need to use. A custom function call makes scripts
easier to read in that case. There's always a balancing act between
readability and functionality though, and everyone has their own preferences.

There is a difference between MC and HC when calling native functions.
In HC, functions written with "the" are sent directly to HyperCard,
while functions that use parentheses traverse the message hierarchy.
That means it matters which way you write them; if you write them with
parentheses, they take longer but they can be trapped later on in a
handler farther up the hierarchy (not a great scripting technique, but
it can be done.) On the other hand, MC sends all its native commands and
functions directly to the engine; that's why you can't intercept and
trap any MC keywords. So in MetaCard, it doesn't matter whether you
write "the length of thisWord" or "length(thisWord"), they are equivalent.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the metacard mailing list