There are multiple ways to skin a cat, but obviously there are some differences between using making Add-Ons and using a FOR loop to jump though repetitious logic:
Add-Ons:
- Seems less "transparent"
- Seamless passing of input / output parameters
- Everything is bundled into the control structure
- Executed on a per instruction basis, and instantized
FOR Loops:
- Require logic to handle passing of parameters to each instance, and potentially the use of multiple UDTs.
- A little more "transparent"
- Execution of the FOR loop must complete in full (unless a Break instruction is encountered).
I'm wondering when would it be appropriate to use one over the other? What is considered a "best" practice, or does it really depend on the coding style / philosophy?
For example, in the past I've encountered code that uses a FOR loop to index through logic for over 100 valves (an element of a custom Valve UDT was used for each increment of the index). Each increment of the FOR loop was a different valve.
On the other hand, in the same program, the analog scaling routines were made into an Add-On instruction, and there was a ladder that had 50 to 100 instances of the Add-On in a row to handle each analog signal.
Are there any major advantages / disadvantages of one method over another? What about effects on scan time?
In something like a Motion Control application where scan time is a major concern, would one be preferable over another?
I'd be interested to hear thoughts on this...
Thanks.
Add-Ons:
- Seems less "transparent"
- Seamless passing of input / output parameters
- Everything is bundled into the control structure
- Executed on a per instruction basis, and instantized
FOR Loops:
- Require logic to handle passing of parameters to each instance, and potentially the use of multiple UDTs.
- A little more "transparent"
- Execution of the FOR loop must complete in full (unless a Break instruction is encountered).
I'm wondering when would it be appropriate to use one over the other? What is considered a "best" practice, or does it really depend on the coding style / philosophy?
For example, in the past I've encountered code that uses a FOR loop to index through logic for over 100 valves (an element of a custom Valve UDT was used for each increment of the index). Each increment of the FOR loop was a different valve.
On the other hand, in the same program, the analog scaling routines were made into an Add-On instruction, and there was a ladder that had 50 to 100 instances of the Add-On in a row to handle each analog signal.
Are there any major advantages / disadvantages of one method over another? What about effects on scan time?
In something like a Motion Control application where scan time is a major concern, would one be preferable over another?
I'd be interested to hear thoughts on this...
Thanks.