From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code


@JÞB wrote:

For the first, a 0 iteration for loop outputs default data ftor the type of any output tunnels.


You get the same with a case that uses output tunnels that are set to use default if unwired. (but that was not available many (many!) versions ago. How old is this code?)

 

The ">" construct on the button labeled "Zero" probably means that the mechanical action is not latch. Thus the need for detecing a FALSE>TRUE transition. The incorrect latch action could mean that there are local variables and value properties elsewhere.

 

And yes, the "AND TRUE" is of course a noop, just returning the other input inchanged.

 

It is difficult to judge code from two small cropped sections and verbal descriptions. If you think we could contribute with more tips, feel free to post some of the VIs.

0 Kudos
Message 1791 of 2,571
(10,311 Views)

@markconigliaro wrote:

Being new though, I have to ask is there something I'm missing? Are these old school techniques or is there actually some purpose to these that I'm missing?


The person who developed the code was either a bad programmer, or far too inexperienced for the task.  I'm not saying all programmers who use 1 iteration loops are bad, there are reasons (few and likely not this case but still).  But if you are and'ing a boolean to a constant...then you need to take CS 101, or Digitals 101, or a high school electronics or computer class.  Anyway feel proud of yourself being able to recognize code smell.

0 Kudos
Message 1792 of 2,571
(10,305 Views)

It's nice to know I'm not crazy. I'll be back in the office on Tuesday, where I'll post a bigger sample of some loops that have a bunch of these kinds of things combined. 

 

I can say some things from memory though. Jeff, the for loops have no outputs. They're all just a single iteration for loop that generates a number or turns something on/off. And altenbach, all buttons are set to "switch until released", and I can't post "some of the VIs" because it's 1 huge, massive VI with no subVI's at all! I don't think a 60 inch TV/monitor would be able to show the whole thing. 

0 Kudos
Message 1793 of 2,571
(10,285 Views)

@Hooovahh wrote:

@markconigliaro wrote:

Being new though, I have to ask is there something I'm missing? Are these old school techniques or is there actually some purpose to these that I'm missing?


The person who developed the code was either a bad programmer, or far too inexperienced for the task.  I'm not saying all programmers who use 1 iteration loops are bad, there are reasons (few and likely not this case but still).  But if you are and'ing a boolean to a constant...then you need to take CS 101, or Digitals 101, or a high school electronics or computer class.  Anyway feel proud of yourself being able to recognize code smell.


I have to commit that I sometimes use the 'and with a boolean constant.

In cases where you want to debug some code and you have a Init/Firstrun input , the 'AND with boolean constant'  is a nice way to overrule that input.  After debugging one could have deleted it , but simply leave the constant TRUE usually doesn't hurt.

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 1794 of 2,571
(10,271 Views)

One plausible reason that someone put in an AND TRUE is that they were ANDing with some other condition in the past.  Perhaps they need to force that to be true while debugging or modifying their logic.  Eventually, they got to a point where they never needed to put the other logic back in, but never got around to stripping that out and now it is just an artifact left over from previous code.

0 Kudos
Message 1795 of 2,571
(10,250 Views)

In cases like those I usually use a disabled diagram structure, and have a case where there is a true constant, I might then put the #debug bookmark in the case as well.  If you did choose to do it your way you could still place a code comment stating what you are doing and it would justify the odd looking bit logic.

0 Kudos
Message 1796 of 2,571
(10,220 Views)

I ran into this one in some legacy code I inherited.  It was to convert data coming back from Modbus into floating point...

ByteRG.png

0 Kudos
Message 1797 of 2,571
(10,201 Views)

@BowenM wrote:

I ran into this one in some legacy code I inherited.  It was to convert data coming back from Modbus into floating point...

ByteRG.png


Careful.  Notice that the 0 index was not used.  So you need to delete that element before you rotate.


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 1798 of 2,571
(10,195 Views)

@crossrulz wrote:


Careful.  Notice that the 0 index was not used.  So you need to delete that element before you rotate.


You are correct, sir. 

 

The lower snip came from my code.  I'm using a newer Modbus package.  The old one returned an array of u8 with element 0 being the number of bytes per data point.

 

The new one just returns an array of u16.  I should have modified it to be identical before posting though 🙂

0 Kudos
Message 1799 of 2,571
(10,187 Views)

BowenM wrote:

The lower snip came from my code.  I'm using a newer Modbus package.  The old one returned an array of u8 with element 0 being the number of bytes per data point.

 

The new one just returns an array of u16.  I should have modified it to be identical before posting though 🙂


If you have an array of U16, then you only rotate 1 element.  Or you could use Reverse 1D Array.


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 1800 of 2,571
(10,182 Views)