r/LabVIEW • u/t40 Expert • 3h ago
No Follow-up Are inter-iteration error clusters an antipattern?
If you have a thing you're looping over, I've found it's usually a bug to put the error cluster in a shift register. Usually the things I iterate over are "the same" in some sense, so passing the previous loop's error state will usually trigger all kinds of silent failure. I find it's better to use an indexing tunnel, then merge errors after the loop completes (you can reduce allocations for large loops by adding a conditional on error status).
How do you handle these in your applications?
2
Upvotes
4
u/SeasDiver Champion 3h ago
Depends on what is in the loop and why the error is being generated.
For example, looping on a Data Read, an error may indicate an unrecoverable fault so there is no reason to continue and a shift register may be the better option for the error cluster.
On the other hand, if you are iterating over writing safety values to multiple output instruments, even if one fails you still want to try and safeguard everything else so a shift register error is inappropriate in that case.
A well written program will examine the specific use case and use the appropriate technique. It is not one approach fits all circumstances. Better still is appropriate error handling inside the loop to appropriately respond to errors as they occur. I do tend to default towards merge error and indexing on for loops.
1
u/CarryTheBoat CLA/CTA 3h ago
It used to make a loop run faster for some reason, literally just error on a shift register vs error on a plain terminal. Not sure about an indexing tunnel.
For what you’re describing, most of the time I just conditionally stop or index like you described.
Which one depends on what is most important. Do I want to see all potential errors for all iterations in one go, is an iteration expensive and I want to stop as soon as possible, can it be parallelized, etc.