# Best Practice: Script or Expression

**URL:** <https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [June 12, 2024, 5:09pm UTC](https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764 "2024-06-12T17:09:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Kuss](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Matthew\_Kuss](https://forum.inductiveautomation.com/u/Matthew_Kuss)\
**Post date:** [June 12, 2024, 5:09pm UTC](https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764/1 "2024-06-12T17:09:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steven\_Cheron](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@Steven\_Cheron](https://forum.inductiveautomation.com/u/Steven_Cheron)\
**Post date:** [June 12, 2024, 5:13pm UTC](https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764/2 "2024-06-12T17:13:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 12, 2024, 5:29pm UTC](https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764/3 "2024-06-12T17:29:19Z")

</div>

> [@Steven\_Cheron](#):
>
> I don't know which onw is faster

Expressions are faster, always.

> [@Steven\_Cheron](#):
>
> I use script when I need conditions, loop or advanced function that expression don't give.

If you can use the [Automation Professionals Integration Toolkit](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) 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.

> [@Matthew\_Kuss](#):
>
> 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?

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

Just use a pure expression binding.

```python
hasRole('role')

```

For more perspective performance infomation see this thread:

> [@Building for Performance](https://forum.inductiveautomation.com/t/building-for-performance/71082/3):
>
> In this example, #3 is the most performant, though it could be argued that the performance gain in this instance would be negligible. Anytime you add an additional processing step you add latency. In general for the best performance I follow these guidelines: If you can achieve what you want with a binding, use a binding. Always use the binding type that is the most direct. (e.g. if all you need is a binding to a property use a property binding, not an expression binding.) Given the choice b…

---

<div class="post-metadata">

**Author:** ![Steven\_Cheron](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@Steven\_Cheron](https://forum.inductiveautomation.com/u/Steven_Cheron)\
**Post date:** [June 12, 2024, 5:41pm UTC](https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764/4 "2024-06-12T17:41:47Z")

</div>

> [@lrose](#):
>
> If you can use the [Automation Professionals Integration Toolkit](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) many of those limitations are also eliminated (e.g. iteration)

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

---

<div class="post-metadata">

**Author:** ![Matthew\_Kuss](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Matthew\_Kuss](https://forum.inductiveautomation.com/u/Matthew_Kuss)\
**Post date:** [June 13, 2024, 1:16pm UTC](https://forum.inductiveautomation.com/t/best-practice-script-or-expression/91764/5 "2024-06-13T13:16:18Z")

</div>

Thank you all for the great information!
