Best Practice: Script or Expression

Generically, is it better to use a script or an expression when performing a transform in Perspective? In most cases I can use either one, but my personal preference is scripts. Is there a reason why I should be using an expression if possible? Is it faster? Does it handle multithreading better? Is there another reason for one over the other?

The most current example is I'm trying to set a button visibility based on the user role. I've bounded the role to the visibility property but then need to transform it to a Boolean value using an if statement. Does it matter what type of transformation I use for this?

I don't know which onw is faster.

But personally, I use expression when it's simple (concatenation, simple math operation, etc...).

I use script when I need conditions, loop or advanced function that expression don't give.

2 Likes

Expressions are faster, always.

If you can use the Automation Professionals Integration Toolkit many of those limitations are also eliminated (e.g. iteration)

Generally, avoid transforms if possible, and default to pure expressions.

You can not do multithreading in expressions. There are certain applications which the expression language is not capable of, in those cases you will need to use scripts.

This is a perfect example of when you don't even need a transform at all.

Just use a pure expression binding.

hasRole('role')

For more perspective performance infomation see this thread:

9 Likes

OH ! I didn't know this module ! Maybe I should try on my next project !
Thank you !

2 Likes

Thank you all for the great information!