Jump to content
Sign in to follow this  
El_Pablo

Mandatory variable declaration

Recommended Posts

Wouldn't be nice if Filemaker would make variable declaration mandatory? Or at least a script step à la "Option Explicit"?

This could prevent many typos bug!

Share this post


Link to post
Share on other sites

You have to declare a Variable in a script, via the Set Variable step, and you have to declare them in a calculation, via the Let () function.

What would be nice is to see is some kind of testing within the script, so that if you try to USE a variable which has not been declared, it is considered a "warning." I don't mean checking for a value; that is different.* Within the script it could be like the If [] End If test.

Of course this assumes that FileMaker could do this. There may be engineering reasons why is it not possible (nor even desirable), especially when you use a script Variable within a calculation. You can declare a variable without using the Set Variable step. For example, this Set Field [ calculation ] works to set a variable, which can then be seen by later script steps.

Let ( $donuts = "glazed"; Left ( $donuts; 0 ) )

That would be pretty difficult for FileMaker to evaluate when you Saved the script. Perhaps at "runtime" via Script Debugger would be easier, and sufficient for developers. You can pretty much tell if a variable is set using Script Debugger right now. But you have to have conditions where it would have a value, and watch carefully. So, it's not that we have no tools to test this.

It would also need to poll for $$global_variable existence also, ie., declared anywhere within FileMaker.

It would have to be a "warning" or "caution", not an "error", if this was done at Save time. Because otherwise you could not include a variable in a test without it being declared earlier. I imagine all of us have done that, thinking, "I'll have to go back and set this." Sometimes, in the case of a global variable, it may be set in another script entirely. Hence it would have to be a warning. It could be an "error" at runtime however, via Script Debugger.

One thing we would not want it to do would be to limit any current or future flexibility of use.

* In AppleScript variables can be declared on the fly, little testing at compile time. But at runtime asking for a variable which has no VALUE in most tests is a runtime error, unless you explicitly set it to a null value in that case. This can be annoying. But you can bypass that error by checking it with the exists Boolean test.

Share this post


Link to post
Share on other sites

What I was thinking of is splitting the "Set variable" step in two.

Something like "Set variable" used to declare variable and "Assign value" used to assign a value to the variable. This way, it could block the double assignment of a variable.

In most programming language, it is not possible to declare a variable twice.

Example ???

dim my_var = 5;

... some code ...

dim my_var = my_var + 5 ' Would cause an error before execution.

Having a syntax analyzer for the scripts could reduce development error.

Hope this could explain my point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.