BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code


@Steve Chandler wrote:

Wow what a reaction! You are all right - definitely readability is the most important thing. I think someone said that bad object code and bad source code make a Rube Goldberg. I disagree. Code readability is the most important thing as long as the object code works as expected.

 

The example I used was a bad example. I should not have picked on such a benign little piece of code.

 

BUT!!!

 

It reminded me of something that I very recently had to deal with. Below is an actual example (constants changed to protect the guilty) of a de-rubitization that I performed a while back. Notice that in the non-rube I still concatenate two constants.

 

The innocent little piece of code brought back some bad memories.

 

 


Aah, well there is bad code and BAD code 😛

 

_____________________________
- Cheers, Ed
Message 1061 of 2,635
(11,360 Views)

Good one Steve.

 

I just wanted to point out that the definition of a Rube Goldberg is something that is (intentionally) implemented in a complicated or superfluous way.  I should look up the wiki definition for a clearer description:

 

"is a deliberately over-engineered or overdone machine that performs a very simple task in a very complex fashion, usually including a chain reaction"

 

Nowhere in this definition does it mention "bad".  So there is good code & bad code.  And the is Rube code and optimized code.  But there is also good Rube code and bad Rube code.  Even the word "bad" needs to be defined. 

 

So I will define "bad" as:

non-working

useless

unreadable

unintentionally overcomplicated that it is not easily readable

unstructured and not meeting recognized standards

obviously undesigned

using Local Variables (I just had to include that one) 😉

and the list goes on based on personal preference...

 

I'm sure there are plenty of books which describe the difference between good & bad code.

 

With all that being said, since this is the Rube Goldberg thread, we will surely see good & bad RG's as long as the code is overcomplicated or overdone.

 

Maybe we should start a "Bad Code Example" thread.

Message 1062 of 2,635
(11,354 Views)

You have to love a code construct like the following.

 

event_Do_While.JPG



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 1063 of 2,635
(11,351 Views)

@Steve Chandler wrote:

Wow what a reaction! You are all right - definitely readability is the most important thing. I think someone said that bad object code and bad source code make a Rube Goldberg. I disagree. Code readability is the most important thing as long as the object code works as expected.

 

The example I used was a bad example. I should not have picked on such a benign little piece of code.

 

BUT!!!

 

It reminded me of something that I very recently had to deal with. Below is an actual example (constants changed to protect the guilty) of a de-rubitization that I performed a while back. Notice that in the non-rube I still concatenate two constants.

 

The innocent little piece of code brought back some bad memories.

 

Example_VI_BD.png


 

A diagram clan-up on the verbose version would make that very readable.

 

Messy will always loose out.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 1064 of 2,635
(11,340 Views)

@yenknip wrote:
Aah, well there is bad code and BAD code 😛 

I am sure Ben and others read that as "bad dog, BAD dog". 😄

Message 1065 of 2,635
(11,329 Views)

I tried cleanup. It does help a lot but readability is only part of it. It is still hard to add things in the middle. It isn't that hard but I am lazy that way. Also for me it is easier to read code if there are less wires. Don't get me wrong - I like wires! I just don't like when there are too many of them because it makes me dizzy. The original could have at least concatenated the semicolon and linefeed separately and wired the output between each constant in the other concatenate. I still don't like it because there is a wire going to way too many nodes.

 

Now that I think about it the thing that bothers me about concatenating a bunch of constants is when you have something like a linefeed between each.

 

I would much prefer even this way.

 

Example_VI_BD.png

 

 

 

=====================
LabVIEW 2012


0 Kudos
Message 1066 of 2,635
(11,329 Views)

Steve.

 

try this first

 

Untitled.png

I'm not sure why the default clean-up parameters were chosen- play around with them a bit and Ctrl+U gets better


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

I tried those settings but didn't like the result. Maybe I will try to tweak the settings but I very seldom use cleanup. When I do it is on other peoples code Smiley Very Happy

=====================
LabVIEW 2012


Message 1068 of 2,635
(11,315 Views)

@Steve Chandler wrote:

I tried those settings but didn't like the result. Maybe I will try to tweak the settings but I very seldom use cleanup. When I do it is on other peoples code Smiley Very Happy


I'm the same way.  If the error wire isn't perfectly straight from ErrIn to ErrOut, there'd better be a damn good reason for being even 1 pixel off. Smiley LOL

 

(kinda the reasoning behind my "align objects by error wire" idea)

0 Kudos
Message 1069 of 2,635
(11,298 Views)

@Steve Chandler wrote:

I tried cleanup. It does help a lot but readability is only part of it. It is still hard to add things in the middle. It isn't that hard but I am lazy that way. Also for me it is easier to read code if there are less wires. Don't get me wrong - I like wires! I just don't like when there are too many of them because it makes me dizzy. The original could have at least concatenated the semicolon and linefeed separately and wired the output between each constant in the other concatenate. I still don't like it because there is a wire going to way too many nodes.

 

Now that I think about it the thing that bothers me about concatenating a bunch of constants is when you have something like a linefeed between each.

 

I would much prefer even this way.

 

Example_VI_BD.png

 

 

 


 

 

Wait!!  Wait!!  wait!!!

 

You're original solution still holds true to be the better one.  This one is just a cleaned up representation of the same Rube Goldberg. 

So it's still a Rube.  Making it a non-Rube does cause the block diagram to be cleaner. 🙂

 

For me, using the \ display would be better than the vertical tower of letters. I would also use Format Into String.

 

This one does border with...  bad dog...  I mean bad code..  It certainly would not meet our internal coding guideline... and as such, it would be considered bad code.. 

 

0 Kudos
Message 1070 of 2,635
(11,299 Views)