BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code


@altenbach wrote:

The Sudoku solver posted here has a pretty front panel, but the code could probably be reduced to 10% of the current monstrosity of locals and stacked sequences.

 

Here's a quick example:

 

We need to copy a 9x9 Array to a different 9x9 Array. Here's an animation showing the current hard way and a possible alternative. 😄

 


Locals are evil-  wouldn't a property node workSmiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 771 of 2,635
(11,912 Views)

@James W wrote:

@broken Arrow wrote:

To sequentially index an array, so many people wire sequential numbers to individual Index Array functions rather than just expanding the function. I see it all the time, even by experienced wire slingers.


OK - What is wrong with that? If you want really quick traceability of a wire halfway down a large index array function that you are then going to bundle after performing an operation on it, coming back to the code in 6 months time it's really useful to see which index is connected to which wire. Then you KNOW you have done what you intended or can see what the original programmer intended without having to count e.g. 13 lines down the index funtion which indexes 24 lines of a 1x36 array starting at index 5.

James


OK I'll bite.  What's wrong may be any number of the following:

  • Data structure is not cohesieve-  too many unrelated variables bundled into a "god" cluster
  • Operations not abstracted- So you want to operate on yous "god bundle" at the same time and you'll never need to do any independant operations?
  • Poor documentation- even after 6 months the WIRE LABELS will still be there (Thanks Christian - I can't beleive I ever coded without Wire Labels)

"Should be" isn't "Is" -Jay
0 Kudos
Message 772 of 2,635
(11,909 Views)

Did you know that inefficient code can prevent out of memory errors??? 😮

 

The proof is here:

 

While both code alternatives grow the data structures by the same amount per iteration, one does so more efficiently and thus runs into the wall quicker. 😄

 

 

  • The more efficient code runs out of memory very quickly.
  • The less efficient code takes 20-100x longer to run out of memory, simply because the loop rate is significantly slower.
We can conclude that we can solve almost all our of memory errors if we just slow the code down enough. For example if we would place a 100000ms wait into the loop, we should be safe for quite a while 😄

 

 

 

0 Kudos
Message 773 of 2,635
(11,880 Views)

Why use "array subset" when you can use "delete from array" and use the deleted portion, but never use the "array w/ subset deleted"?

 

 

 

 

 

0 Kudos
Message 774 of 2,635
(11,793 Views)

 

 


@for(imstuck) wrote:

Why use "array subset" when you can use "delete from array" and use the deleted portion, but never use the "array w/ subset deleted"?

 

 

 

 

 


Is there any difference in memory uses?

 

 

Regards
Ray Farmer
0 Kudos
Message 775 of 2,635
(11,757 Views)

 


@Ray Farmer wrote:

 

 


@for(imstuck) wrote:

Why use "array subset" when you can use "delete from array" and use the deleted portion, but never use the "array w/ subset deleted"?

 


Is there any difference in memory uses?

 

 


I would think it uses the same amount of memory. Even though you aren't doing anything with the array output, the delete from array function will still allocate the memory and perform that operation. I don't think you would save anything by simply not displaying that data (aside from the memory of the indicator, but you get the point).

 

Cory K
0 Kudos
Message 776 of 2,635
(11,757 Views)

 


Cory K wrote:

@Ray Farmer wrote:

 Is there any difference in memory uses?


I would think it uses the same amount of memory. 


 

Personally, I would not rely on "thinking" here. 😮 Design some careful benchmark instead! 🙂

 

(Did you know that "built array" is orders of magnitude faster than "insert into array" for appending an element to an existing 1D array, even though they do the same thing. Would you have guessed?)

0 Kudos
Message 777 of 2,635
(11,753 Views)

@altenbach wrote:

 

 

(Did you know that "built array" is orders of magnitude faster than "insert into array" for appending an element to an existing 1D array, even though they do the same thing. Would you have guessed?)


This makes logical sense.

A built array just adds data to the end of the existing array,

Insert into array needs to split the array into 2 memory spaces to add the data into a gap in the middle (even if the "gap in the middle" is a gap at  the end between Data and no data.)

- I would expect Insert into array to copy/ the data at least once. Build array should only need to move the array if the data space next to it is already alloacted - insert into array will also haveto perform this check before creating the new array.

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 778 of 2,635
(11,688 Views)

I wonder if it would be the same as comparing Linked Lists and Arrays in C language...

0 Kudos
Message 779 of 2,635
(11,669 Views)

Who needs scalars????

 

We could just use arrays with 1 element each. Same difference!

 

(seen here. Look for Kings law.vi and also Pressure Transducers' Calibration.vi for some confusion)

 

Here's the code of Kings law (top) and a possible alternative (bottom).

 

 

 

0 Kudos
Message 780 of 2,635
(11,536 Views)