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.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
altenbach

Bleach Dead Code

Status: New

It has come up here in a different discussion, but I think it should be a separate idea, so here it is!

 

If we disable part of the code using the diagram disable structure, the disabled code gets lighter in color. The new compiler is good at eliminating dead code (i.e. things that don't need to be computed because there is no output), so it could be useful if these code parts are also bleached in a similar way to indicate that fact.

 

Here's how it could look like.

 

I would even suggest this to be enabled by default. Of course there also needs to be an option to turn it off....

 

(I was about to write up this idea, but then, searching for "dead code", I found comment by SynchronizationOverhead. So the original credit goes there, of course ;))

7 Comments
Manzolli
Active Participant

Don't think bleach is the best solution because hidden frames in Case Structures, Event Structures, etc., may stay dead until the programmer look in all frames for then.

 

A better solution would be a command like or inside the search toll to find all "dead code".

 

No kudos because since version 2010 is optimized to ignore this dead code, there's no big harm. After all, a good program practice in code has a few or none dead code at all.

André Manzolli

Mechanical Engineer
Certified LabVIEW Developer - CLD
LabVIEW Champion
Curitiba - PR - Brazil
altenbach
Knight of NI

Code typically does not turn dead by itself inside a structure. I would use it as an instant sanity check during coding. It's not just a matter of removing dead code for cosmetic reasons but also to verify correct program flow.

 

For example if some seemingly important code section shows up as dead, we probably have a mistake somewhere.

 

Example 1: I am sure it has happened to most of us if we try to wire to an output, we accidentally wire to one of the inputs caused by an otherwise unnoticed slip of the mouse. So what we think is an output wire, is actually carrying the data going to one of the inputs. With this idea, we can tell immediately that the node is actually not used.

Example 2: I decide to remove some features of a VI, because they are no longer needed. If I start by removing the obsolete output, I can tell immediately what else I can remove without breaking the important stuff.

Dragis
Active Participant

i like this idea. i would definitely want a way to quickly turn the feature on and off during development so things don't keep switching from bleached to normal while i'm editing. perhaps a toggle switch on the toolbar? 

Manzolli
Active Participant

With the examples and an easy toogle button in the toolbar the idea becomes nice. Kudos!

André Manzolli

Mechanical Engineer
Certified LabVIEW Developer - CLD
LabVIEW Champion
Curitiba - PR - Brazil
AristosQueue (NI)
NI Employee (retired)

> A better solution would be a command like or inside the search toll to find all "dead code".

 

There may be a test for this in VI Analyzer. I recall hearing some talk about this, but it may have just been an idea that floated around, not something that ever got implemented. If it was implemented, it'll be in 2010. If someone has 2010 VI Analyzer installed, you might check.

X.
Trusted Enthusiast
Trusted Enthusiast

I just posted a similar idea here, so my apologies for not bringing up my addendum here first...

Basically, I am suggesting having this kind of code identified in the Warning Window (Error window with "Show Warnings" checked).

Dan_Lauber
Member

I generally like this idea, if code will be optimized out by the compiler, it'd be nice to have a hint to the programmer - since that code probably shouldn't be there in the first place. I know it has no ultimate effect at runtime since the dead code isn't compiled, but I think it's a useful hint for keeping code clean and highlighting code you might have thought was doing something.

 

Dragis has a good point, there's going to be lots of dead code generated while wiring, so this might be annoying (or it might not be).  One of the options could be to mark code 'dead' only once you run a VI, but mark it undead as soon as it's wired.