Is it safe to use "Retain nosort" attribute for Interaction Parameters to remove loops from code
Voted best answer
Is it "safe" ? ... Sure. You wont blow anything up (probably)
Will it work ? Maybe, maybe not.
You get "Code Loops" because the compiler cannot determine the correct order in which to execute all your Code Blocks. ( Note: Code Blocks, Not Control Modules ! )
When you set the "nosort" attribute on a variable, you tell the compiler not to sort ANY code blocks that access that Variable.
This means that your code execution order is completely Arbitrary. You have no idea and no control over which code block executes first. And each time you make a change to your code and compile it, the execution order can change.
Sometimes this doesnt matter. Sometimes it does. If you ever use "one shot" logic, where you set a variable for one scan, then it can matter a lot.
Using "nosort" is sometimes required and sometimes makes absolutely no difference to your code. Whether it breaks YOUR code is not something anyone can answer.
I would guess that about 90% of code loops are caused by making your connections wrongly, about 8% are because you didnt break up your program into Code Blocks properly and about 2% are "just because" and you have no choice but to set "nosort" and live with the results.
There is more information about code sorting in the Library Object Style Guide Page 79, and AC800M Planning Manual Section 3 - Programming in Practice.
The question "is it safe to...?" is purely depending on your application and that you have to know. Furthermore the Code Loop can only exist when programming with Control Module and smallest entity where you can have the problem is CodeBlocks (even if they would reside within the same Single Control module, i.e. next to each other from programmers point of view).
Practically it is the question of having variables / connections between these application blocks and then finally a connection back from the last to the first block (that finalises the Code Loop). While have a Code Loop compiler can not determine what is the correct order of executing the application, i.e. what is the first codeblock to be executed. While there is at least one such a connection (or several), you must analyse those connections (variables). At the same time you need to determine (read know), if there is one and only one correct execution order of your application or whether it makes any difference at all.
Based on your above analysis you have two choices:
A) If you know that the application works properly independent of application execution order you can use nosort, in which case you will not know the first code block to be executed. This is because with nosort attribute you hand over the decision to the compiler.
B) If you need to know the exact execution order you need to use state attribute for that variable/connection that creates the code loop. With this attribute you can determine where you use the the new value and where you have the old value from previous scan and by these you can actually set the starting point of the application.
As reference earlier you will find important information from AC800M Planning Manual Section 3 - Programming in Practice. See chapter "Correcting Sorting Problems" carefully. Hope this gives at least some idea.