BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code

Happen to run across this page, comparing C and LabVIEW code for a simple sorting task..

 

 

altenbach_2-1575580465416.png

 

Obviously, it's old (e.g. from the look of local variables and boolean constants) and obviously the authors tried to synchronize the code to more faithfully resemble the C code, which is typically a bad idea. 😄

 

A real LabVIEW programmer would immediately:

 

  • Place the array into a shift register, eliminating all (or most) local variables.
  • Since the array can also be entered manually, it needs to remain a control, so we need one local to write to it (best placed right after the left shift register. The control should replace the local going into the subVI.
  • All cases would just update the array in the shift register.
  • delete the sequence frame because it is no longer needed.
  • ...

(Of course the second version of bubble sort further down could be implemented with an IPE for cleaner code, but that did not exist(?) back then...)

 
0 Kudos
Message 2121 of 2,565
(10,341 Views)

Quoting still not an option...

 

Christian!

 

The Seq is required to ensure the value is placed in the indicator BEFORE the loop starts.

That code shows how we had to do things BEFORE the Event Structure existed.

 

Ben

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

@Ben wrote:

The Seq is required to ensure the value is placed in the indicator BEFORE the loop starts.

That code shows how we had to do things BEFORE the Event Structure existed.


But if you change to use a Shift Register instead, the control/indicator is not even needed.  I once inherited similar code and I reduced execution time to a small fraction just by eliminating local variables by using a shift register instead.


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
0 Kudos
Message 2123 of 2,565
(10,271 Views)

@Ben wrote:

The Seq is required to ensure the value is placed in the indicator BEFORE the loop starts.


That why I said "it is no longer needed" because we already added a shift register in step #1 and now we just initialize it with the array. 😄

0 Kudos
Message 2124 of 2,565
(10,257 Views)

There are many (many!!!) things wrong with this code (Even Darin's patched version fills about 200 screens!).

 

But let's have a look what we would need to do if "boolean array to number" never existed (Yes, this is only a small section. It goes on forever with many (many!) more instances):

 

altenbach_0-1576256206992.png

 

 

Similarly, how many times do we need to read the same values via local variables in parallel?

 

altenbach_1-1576256377235.png

 

 

This thing is straight out of the twilight zone. Who would ever program like that???

The entire code could probably be reduced to one screen, even a postcard!!

 

Message 2125 of 2,565
(10,198 Views)

@altenbach wrote:

This thing is straight out of the twilight zone. Who would ever program like that???


The only excusable situation (pretty sure that's not what happened here) is when scripting was used to generate the code from a (text\excel) script. The 'beauty' of such a tool is that if it works for small scripts, it will simply gets bigger for large scripts. Until it gets too big (extending diagram limits).

 

Even then, I'd change the scripting to produce something more decent.

0 Kudos
Message 2126 of 2,565
(10,207 Views)

Stumbled across this old thread (2010), and it seemed difficult to imagine that calculating the angle between two lines would really need three linear algebra and one trigonometric function (top of image).

 

As a public service announcement, here's how to get the same result using (simple!) complex math (bottom of image). 😄

 

altenbach_0-1576433602118.png

 

Message 2127 of 2,565
(10,187 Views)

@altenbach wrote:

There are many (many!!!) things wrong with this code (Even Darin's patched version fills about 200 screens!).

 

But let's have a look what we would need to do if "boolean array to number" never existed (Yes, this is only a small section. It goes on forever with many (many!) more instances):

 


The worst part about that is that the developer clearly knew "Number to Boolean Array" existed as it was used elsewhere in the code.

 

BowenM_0-1576699877459.png

 

 

Side note, I can't even imagine how someone would develop and debug a VI like this. 

 

 "Oh, there's a bug.  I think that section of code I need to move my horizontal scrollbar about 82% to the right, vertical about 24% down, and then go to that stacked sequence structure and select sequence 28"

 

I can only imagine that VI took months to develop. Looking at what it actually does, I would expect a couple weeks at most.

0 Kudos
Message 2128 of 2,565
(10,089 Views)

BewenM wrote;

 

"

I need to move my horizontal scrollbar about 82% to the right, vertical about 24% down,

"

I have had to support code like that!

 

The customer added letters across the top and numbers down the side so he could say "go to F7".

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2129 of 2,565
(10,044 Views)

@Ben wrote:

BewenM wrote;

"I need to move my horizontal scrollbar about 82% to the right, vertical about 24% down,"


Coloring the diagrams should work really well combined with the navigation window. 

 

Simply make high risk zones red, followed by orange, yellow and green. If there's a bug, navigate to the red zones, and work you're way down!

 

(/S, if that isn't obvious.)

 


@Ben wrote:

The customer added letters across the top and numbers down the side so he could say "go to F7".


Those label arrows work nice for that. Place them outside all the structures, and point the label arrows inside. Double click the line of the arrow to go to the code. That works nicely as bookmarks (but faster than actual bookmarks).

 

I actually did this a few times. Works wonders in state machines. But I usually delete them when moving to the next issue.

 

Don't tell that to whoever needs tricks like this, it might be misinterpreted as encouragement.

Message 2130 of 2,565
(10,023 Views)