Overhaul custom functions --or-- replace them with scripts called from calcs!

Idea created by disabled_davidthorp on Dec 28, 2015
    Active
    Score-8

    Custom Functions are great at what they do, but they have some inherent frustrations:

     

    1. Can't access a custom function in any file other than the one it's defined in.
    2. No organization - no separators, folders, etc. like Scripts, Layouts, etc. now have.
    3. Wasn't updated with the FM14 updates to the calculation engine/dialog.
    4. Recursive call limits
    5. Possibly others.

     

    I say fix those issues, or... to be honest, I can see a vision where we dispense with custom functions completely and replace them with scripts.  The calculation engine could include the ability to call a script and return a result inside a calculation, instead of custom functions.

     

    There's nothing a custom function can do that a script can't do, other than the fact that it can be typed elsewhere into a calculation.  Other than that, at the end of the day a custom function processes a bunch of information and returns a result.

     

    So why not dispense with custom functions altogether, and simply have a native FileMaker function in the calculation engine that performs a script?  The result of this function is the result of whatever the script does. It sounds far fetched at face value, but we used to be able to do that with plugins, so is it really?

     

    It's a pretty big paradigm shift and might even require a new file format, or at least some sort of automated conversion process.  The conversion process wouldn't be that difficult though:

     

    Every custom function that has ever been written can be written as a script simply by:

    1. Figure out how we're going to handle multiple parameters in scripts (like this: Native Multiple Parameter Passing for example)
    2. Then replace each function with a similarly named (and parameterized) script that has, if nothing else, simply one step: Exit Script[...] where "..." is whatever was in the custom function.

     

    (One exception here, and that is recursive custom functions.  But scripts can recursively call themselves, so depending on the implementation of the recursion in each custom function, this too can be replicated in scripting one way or another.  Recursion is simply a matter of having an If or Case statement that determines when it calls itself vs when it exits.  Scripts have If/Else If/End If to replicate that so with some careful analysis, these could potentially be automatically converted also).

     

    Ideally, the PerformScript() function would somehow be able to tap into the Specify Script dialog, rather than have the script name (and parameters) manually typed in - or, if script names can be treated like field names, TOs, and how functions are currently handled, then it would simply be a matter of starting to type the script name in, and having the type-ahead popup thing come up now to fill in the script name just like we do currently with fields, TO's, etc.  And the reference should be by internal ID not by the name itself, just like fields, TO's, etc. so that if we ever change the name of a script, the change is reflected in every calculation that references it, just like with fields, TO's, etc. now.

     

    (Ultimately, could all FileMaker's built in functions like the Left (...) function etc. also become scripts or script steps?)