BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code


@Ben wrote:

you can just right click and choose "duplicate case".

I do this a lot (of course, not copying the variables but only the respective unbundle/bundle nodes or other functions), to keep code clean, which, I call "code mirroring", since the different functions/SubVIs remain on the same coordinates when we Mouse+ScrollWheel through the different cases of the State Machine case structure without getting eye-pain. Smiley Happy

 

PFA the VI to see what I mean.

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 1901 of 2,571
(10,377 Views)
0 Kudos
Message 1902 of 2,571
(10,286 Views)

A colleague called me over to help him with a jig that he fired on for the first time since the Christmas holiday. The test software was written by a former colleague, and whilst I don't officially support it, I have been dragged over to have a look at it occasionally, holding my head in my hands as I do.

 

I managed to trace back the error code being reported to the RS232 barometer. A hastily written test panel showed it was responding correctly, so flicking through the code found me here:

 

rube-str-comparison.png

 

I understand that there was a failure mode whereby the device returned odd string values (units are in Pa, so typically should be 101 000 or so), hence the attempt at a trap for unexpected values. I have never seen anyone use a GTE comparison on a string to check this, as only the first two characters are compared. Values between 100 kPa and 170 kPa are passed correctly; values between 17 kPa and 100 kPa are not.

 

As atmospheric pressure is hovering around 98/99 kPa, which is hardly unexceptional around here, and there is plenty of turbulent air in the vicinity of the barometer, it's a teeny tiny bit of an oversight. I'm just surprised they've never seen the issue before!

---
CLA
Message 1903 of 2,571
(10,245 Views)

I had no idea you could even do a GTE comparison of strings. Is it just comparing the ASCII values?

Matt J | National Instruments | CLA
0 Kudos
Message 1904 of 2,571
(10,237 Views)

Comparisons on string behave strangely. It checks the first character of both strings, if greater, result is true, if less, result is false, if equal, check second characters. Repeat. 

 

I'd agree, it makes a lot more sense to convert to numeric first then do the comparison. 

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

Message 1905 of 2,571
(10,230 Views)

That's merely the easiest of the Rubes to show.

 

The top level VI as a whole reminds me of a favoured series of XKCD comics:

code_quality

 

 

 

---
CLA
Message 1906 of 2,571
(10,208 Views)

@Jacobson-ni wrote:

I had no idea you could even do a GTE comparison of strings. Is it just comparing the ASCII values?


How else would the sort 1D array work on strings?

0 Kudos
Message 1907 of 2,571
(10,175 Views)

The task is to create a histogram of about 1M random numbers from 1..69.

 

We could do it with four FOR loops with the inner FOR loop pumping hot air most of the time (seen here)....

 

RNGHistogram

 

Or we could do it all in a single loop ....

 

HistoGen.png

 

 

Message 1908 of 2,571
(10,124 Views)

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:Flush Queue 10000.png

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.

 

Message 1909 of 2,571
(10,013 Views)

@nathand wrote:

 Better flush the queue again (and again, and again) - 10000 times - just to make sure.


It's the Drano algorithm. 😄

Message 1910 of 2,571
(10,009 Views)