BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code


nathand wrote:
The Read ADC case constantly enqueues "Read ADC". How do you stop it? Flush the queue, remove all the "Read ADC" elements, and put everything else back in the queue. But what if the consumer loop executed again while flushing the queue? Better flush the queue again (and again, and again) - 10000 times - just to make sure.

Not to mention those property nodes in the for loop. Those will synchronise with screen updates, making the loop dramatically slow. Or maybe it's supposed to be slow? Could be a bug making the faulty design "work"?

0 Kudos
Message 1911 of 2,574
(10,512 Views)

@nathand wrote:

We ordered an evaluation kit for a particular component, and the manufacturer provided a nice GUI to test it. I was excited to discover that the code for their application is available for download on their website. Then I looked at the code and found this unusual approach to stopping a queued state machine:

 

200px-Ouroboros_1

 

Spoiler
The Read ADC case constantly enqueues "Read ADC". How do you stop it? Flush the queue, remove all the "Read ADC" elements, and put everything else back in the queue. But what if the consumer loop executed again while flushing the queue? Better flush the queue again (and again, and again) - 10000 times - just to make sure.

 


"say no more, say no more"

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 1912 of 2,574
(10,488 Views)

This isn't really a Rube Goldbergian construct, more an oversight in a KB (their image, not mine, and not my highlight for Buffer Size): 

 

 

I will accept that the auto-indexing input to the For Loop is definitely non-zero in this case, but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?

 

Source

---
CLA
Message 1913 of 2,574
(10,386 Views)

@thoult wrote:

but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?


Not to mention the error wire. It needs a shift register, or a parallel shift register with merge error inside...

Message 1914 of 2,574
(10,375 Views)

wiebe@CARYA wrote:

@thoult wrote:

but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?


Not to mention the error wire. It needs a shift register, or a parallel shift register with merge error inside...


The explanation I've heard for this is because a FOR loop can actually execute ZERO times, so stuff on the left doesn't propagate to the right.  In case you are wondering how a loop can execute zero times, think of a FOR loop auto-indexing over an empty array...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 1915 of 2,574
(10,331 Views)

billko wrote:

In case you are wondering how a loop can execute zero times, think of a FOR loop auto-indexing over an empty array...


That is correct.  Been burned a few times from this (empty array being autoindexed and my references go bye bye).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 1916 of 2,574
(10,312 Views)

So what is the solution here then?

 

On the one hand you would want the error to move through each iteration of the for loop, but on the other hand a zero-sized array wouldn't carry the error from one side to the other.

 

 

0 Kudos
Message 1917 of 2,574
(10,307 Views)

@billko wrote:

wiebe@CARYA wrote:

@thoult wrote:

but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?


Not to mention the error wire. It needs a shift register, or a parallel shift register with merge error inside...


The explanation I've heard for this is because a FOR loop can actually execute ZERO times, so stuff on the left doesn't propagate to the right. 


So errors on the left not coming out is a feature? That is evil. People advocating this should be forbidden to program in LabVIEW for life (after a warning, have to allow people to make mistakes)).

 

Try debugging that: the error in propagates just like it should, but only if the for loop executes 0 times (very likely caused by an error), the error is cleared! Even no error handling would be better.

 

 


@billko wrote:
In case you are wondering how a loop can execute zero times, think of a FOR loop auto-indexing over an empty array...

I'm quite familiar with that. Probably a lesson I learn in my third week of LabVIEW programming (maybe slightly misjudging by the subsequent decades). The lesson being: use a shift register!

0 Kudos
Message 1918 of 2,574
(10,306 Views)

I should probably have clarified in my post, I meant non-zero length! 🙂

---
CLA
0 Kudos
Message 1919 of 2,574
(10,293 Views)

@sebster wrote:

So what is the solution here then?

 

On the one hand you would want the error to move through each iteration of the for loop, but on the other hand a zero-sized array wouldn't carry the error from one side to the other.

 

 

Shift registers on both the error and reference tunnels are the way forwards, as they will be passed through even if the loop never executes.

 

Edit - sorry, missed your 'On the one hand' - wiebe's point about having a parallel wire carrying the initial error with a shift register, then a merge afterwards, feels sensible.

---
CLA
Message 1920 of 2,574
(10,290 Views)