BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code


@altenbach wrote:

 

(seen here)

 

Try to simplify this while loop 😄 😮

 

 

 

(It is important to know that the "array" indicator gets reset to default upstream somewhere in an earlier frame of a long flat sequence.)


I'll take that as "Maintain the Values and size of array as is" 

Who needs a loop?

Spoiler
Who needs a loop.png

"Should be" isn't "Is" -Jay
Message 1521 of 2,571
(10,421 Views)

@JÞB wrote:

I'll take that as "Maintain the Values and size of array as is" 

Who needs a loop?

 

Who needs a loop.png


I didn't check the code, but I expect your version is actually incorrect (Jeff, you shouldn't be failing these classic CLAD questions Smiley Surprised ).

 

I think a simpler option is (array size+2) into a for loop and simply output the i as auto indexing, which I expect would perform better than your code, because there are fewer operations.

 

Now, whether those two extra elements are actually desirable or there from lack of understanding is another matter.


___________________
Try to take over the world!
0 Kudos
Message 1522 of 2,571
(10,402 Views)

I would just use the Ramp function...


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 1523 of 2,571
(10,381 Views)
oh ye of little faith. you missed that the wire out of riffle via is an index

"Should be" isn't "Is" -Jay
0 Kudos
Message 1524 of 2,571
(10,358 Views)
oh ye of little faith. you missed that the wire out of riffle vi is an index. Useful function that riffle vi

I like to show it off now and then.

Ramp would be the best choice. I figured someone else would demonstrate it

"Should be" isn't "Is" -Jay
0 Kudos
Message 1525 of 2,571
(10,354 Views)

@JÞB wrote:
oh ye of little faith. you missed that the wire out of riffle via is an index

I think Yair's point was that the original RG code actually creates an output array that is two sizes too large. The loop only stops after [i] > N. Of course this is incorrect for the application where it was originally used, but in order to make your code equivalent, you need to add two elements. 😉

0 Kudos
Message 1526 of 2,571
(10,369 Views)

@altenbach wrote:

@JÞB wrote:
oh ye of little faith. you missed that the wire out of riffle via is an index

I think Yair's point was that the original RG code actually creates an output array that is two sizes too large. The loop only stops after [i] > N. Of course this is incorrect for the application where it was originally used, but in order to make your code equivalent, you need to add two elements. 😉


Yup, I totally overlooked the silly logic and wired that as a "less than" in my head


"Should be" isn't "Is" -Jay
0 Kudos
Message 1527 of 2,571
(10,358 Views)

I found this gem in some old company code today.  Because using Typedefs and enums is too easy.  Oh and shift registers.

 

Huh.png

 

The best part is that's barely even scratching the surface of what's wrong with this code.

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 1528 of 2,571
(10,283 Views)

Well at least they knew they could use the scan from string to perform the string to enum conversion.  I've seen many developers not know that...but yeah they should know that you can have an enum constant.  Oh but I bet that the compiler is smart and does constant folding to replace the string constant with an enum constant...not that it makes it any better.

Message 1529 of 2,571
(10,278 Views)

I like it!!

Although I would go so far as to suggest that this would not necessarily be a Rube every time. If you have 2 enums, one of which is applicable to this VI, and one of which is applicable to the whole project (or multiple projects) then the values in the eunms might not be the same even though you can guarantee 2 cases the same.

as I said, I like it... in the right circumstances it has its place! (probably just not where you found it!

 

James

 

<edit> (by it I mean the method of converting an enum via a string back into an enum!)

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 1530 of 2,571
(10,213 Views)