Re: Script parameters vs global variables
- From: d-42 <db.porsche@xxxxxxxxx>
- Date: Sat, 22 Sep 2007 12:53:09 -0700
On Sep 22, 5:23 am, Matt Wills <I...@xxxxxxxx> wrote:
On 09/21/07 6:02 PM, Chris Brown wrote:
Matt Wills wrote:
but I have yet to see anything
so simple and elegant as a Custom Function (assuming you have the
capability) athttp://www.BrianDunning.com(from the Tim Anderson Group):
GSP (num) =
Case (
num = 0 ; Get ( ScriptParameter ) ;
GetValue ( Get ( ScriptParameter ) ; num )
)
You define the parameters as a return-separated list of values using
the pilcrow:
"Red¶Yellow¶Orange"
so that GSP ( 1 ) returns "Red", GSP ( 2 ) returns "Yellow", etc.
GSP ( 0 ) returns the full list.
Matt
ah, then you haven't seen my custom function then:
Fn Name: GetSP_N
Parameter: N
Definition:
Let([
SP = Get ( ScriptParameter );
LIST = Substitute ( SP ; "|" ; "¶" )
];
GetValue( List ; N)
)
That's probably because you haven't posted it at BrianDunning.com.
One beauty of FileMaker is that there are so many different ways to do
something. The efficacy of a given method has to be measured in terms of
either speed hit or simplicity (what has come to be known as elegance).
There are several Script Parameter functions at Brian's site, some of
which are rather involved, compared to either yours or the one I
supplied. I had one myself, which I asked Brian to remove when I saw Tim's.
Between these two, though, there probably isn't a measurable speed
difference unless you're dealing with thousands of parameters, so how
does one say which is simpler, more elegant?
Yours uses Get ( ScriptParameter ), Substitute and GetValue within a Let
statement. Four functions, two variables, 80 non-space characters.
Reducing the variable to single letters ("S" instead of "SP", "L"
instead of "LIST"), that could be reduced to 70. Side question: Do 8.5
and 9 allow the use of "LIST" as a variable, given that it is a function
itself?
Tim Anderson's uses GetValue and Get ( ScriptParameter) within a Case
Statement. Three functions, one variable, 70 non-space characters,
reduceable to 66 by changing "num" to "n".
One function, four characters. Pretty close.
Actually, assuming things are implemented optimally internally by
filemaker. Tim's is 2x as fast on large data.
As for character count, I wouldn't read much into that. Parsing in
filemaker **from what I can tell** is largely done when you create an
expression, not when you evaluate it. So function names, field names,
table names, etc are all likely pre-parsed into an evalutation tree
which then gets run when it needs to be evaluated.
The exceptions to this are $variable names and of course anything you
put inside an "evaluate()" function. These get parsed and evaluated at
run time. So using field:reallylongnamegoeshere vs field:x is
*identical*. But $variablereallylongnamehere vs $v is not. (However,
the difference between a 1 char variable and a 10 char variable is
generally irrelevant; though it might matter if you were lugging
around 1000 character variable names.
As for the actual functions (without getting into theory):
Case is fast.
Let is fast
Get(ScriptParameter) is fast
GetValue is slow
Substitute is slow
And actually, running the Substitute takes longer than anything else
by a considerable margin.
Of course, I agree, that you'd only ever *see* the difference in a
very long parameter list or a very high iteration loop.
-cheers,
Dave
.
- References:
- Script parameters vs global variables
- From: Carla
- Re: Script parameters vs global variables
- From: Matt Wills
- Re: Script parameters vs global variables
- From: Chris Brown
- Re: Script parameters vs global variables
- From: Matt Wills
- Script parameters vs global variables
- Prev by Date: Re: get (lasterror) not working in 9.0
- Next by Date: Button Script
- Previous by thread: Re: Script parameters vs global variables
- Next by thread: Re: Script parameters vs global variables
- Index(es):