Script Transforms performing ancillary tasks

I recently found a script transform that someone had written that was doing other things in it besides returning a value, like writing values to other tags. My initial reaction was that you should never perform ancillary tasks within a script transform, mainly since you want the GUI components to update as fast as possible, so adding extra stuff will slow down the transform. Additionally, it's not an obvious place to put writes to other tags or other variables like custom session props, making it more difficult to maintain. I would consider it an anti-pattern.

For these things, I would normally use an on value change script on a custom property, or similar.

I wondered though if there's any other reason that these actions shouldn't be performed?

By ancillary tasks, I'm talking about calling:

  • system.tag.write*
  • system.db.runPrepUpdate
  • self.session.custom.propName assignments
  • etc.

I've caught myself doing that exact thing. I love transforms, but it can be tempting to do things you probably shouldn't do.

I've gotten into a habit to use transforms only when necessary, and when I do, use expression vs script... gotta keep Phil happy. :slight_smile:

5 Likes

Well.

Pure vs. Impure. Having side effects and a non-consistent outcome pretty much defines "Impure".

You don't want impure, do you?

6 Likes

The beauty of Ignition, so many tools, but also so many ways to hurt yourself

5 Likes