Expressions and functions side effects

Hello all,

I would like to ask for a clarification on the concept of side effects of executing expressions and functions.

The section Functions and Side Effects on the Expressions page of the Documentation, states various scenarios where functions and generally expression components can be executed more than once.

For that reason, all functions should not modify external systems.

However, what is not 100% clear, is whether or not a Rule Expression that is a component of an expression that is being executed falls under the same side effects category as Functions.

Any ideas?

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    I think the answer to your question is Yes.  Appian gives no guarantees about the order of operations, except in a couple of places, so you want to build expression rules in regard to that fact.  You want to get the same result regardless of what order the steps should take place.  You also want to avoid any consequences to anything else other than the intent of the function / expression only.  You don't want saving a PV to another PV to affect your database in any way.

    For instance, a long time ago I overheard a conversation about two of my colleagues finding a bug.  They had a query in a with() variable, and it, in turn, called a rule that also had a query in a with() variable.  This is why, they found out, each user was running the same query many hundreds to thousands of times whenever they used the form.  It was actually set up to rerun the query; I think it queried the same select statement 101 times every time the user typed a character, and there were something like 20 text fields on the form.  The expression, as written, had the unintended side-effect of taking up connection threads from the thread-pool.

    I believe local variables are evaluated in order from top to bottom, and I know saveInto parameters are evaluated in order from top to bottom.  On the process modeler, a script task's inputs are evaluated in random order (perhaps multiple times), and afterward the outputs are evaluated in random order (perhaps multiple times).  If you need two outputs to be run in a specific order, you have to make 2 script tasks to ensure they do.

  • Thank you for the reply.

    I had that same understanding, but the way that part of the documentation was written focused around the word Function made consider the possibility that rule expressions are not affected in the same way.

    Yes, I have seen myself such cases with the use of the with() function where care was not taken. And it can be difficult to pinpoint it in a large application and even when the Appian platform runs a large number of applications.

  • 0
    Certified Lead Developer

    I think the main context of the conversation there is about the creation of new functions using plugins to extend Appian.  You definitely want your brand new Appian functions coded in JAVA to avoid any side-effects.  However, it still applies to your expressions as well.

    In the case of rules that call queries as inputs, Appian is smart enough to cache query results and prevent some side-effects, but better to design well given a system smart enough to cope with bad design than to design poorly expecting your system to be smart enough to cope with your bad design.  It's better to actively avoid side-effects in all the places you can.