LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
AristosQueue (NI)

Develop a language feature for maintaining an ongoing template relationship between two VIs

Status: New

Software engineering teachers will tell you that you should avoid copying code. Why? Because if there is a bug in the copied code, when you fix the bug, you have to visit many places to apply the fix. But you should copy code when the original function is likely to change in the future and your new code segment would not be happy with that future change.

 

Inheritance of classes is a language feature that developed to address this issue. Each child class "copies" the functions from its parent and then overrides certain functions. For any non-overridden function, if the parent implementation is changed, the child is changed. For any overridden function, if the child implementation does not call the parent implementation, then changes to the parent implementation do not affect the child.

 

But suppose the parent implementation is a case structure on some integer value and the child class wants to do something special in each of the frames. Assume that refactoring the parent class is out of the question -- that may have come from some third party over which the developer of the child class has no control.  The child class cannot override the individual frames of the case structure. The child must override the entire function, have its own case structure for the special values, and then call the parent. This works, but it means at runtime, the program wastes time doing the comparison operation twice. This is a simple case with trivial duplicated effort, but more complex versions can be constructed. And all of this presumes that the function in question is marked as dynamic dispatch in the first place.

 

Now, consider source code control. Developer Alpha writes a function and submits it to the code repository. Developer Beta branches the code repository, syncs the function, edits it, and checks in the modified version. Now Alpha revises the original. Beta can use various merge tools to integrate changes from one branch into the other. When Beta does the integration, he/she may accept changes, may reject changes or may bring them in with modifications.

 

What possibilities exist for a language syntax that allows a developer to specify, as part of the VI, the rules for integrating changes from another VI? In other words, suppose we had a way to create VI Dog1 from scratch, and then create VI Dog2 using Dog1 as a template (which we can do today) but have Dog2 remember that it came from Dog1. Then we could make edits to Dog2. Thereafter, if anyone edits Dog1, Dog2 loads and is a broken VI until the developer does a merge operation to accept/reject/modify the edits made to Dog1. As an editor feature, that would be (relatively) easy to do --- Dog2 just needs to remember Dog1 and have stored enough memory about Dog1's panel and diagram and VI Properties such that when Dog2 loads into memory, it can compare its memory against the Dog1 on disk and break itself if Dog1 has been edited since the last integration.

 

But suppose we went further and specified on the diagram/panel/properties of Dog2 what regions should be handled how. In other words, some portions of Dog2 could be marked as "If Dog1 changes in this region, just update these portions automatically" or "ignore any edits made to Dog1 in this region" or "Ask me how to handle any changes in the code and break the VI until I answer." The regions would likely have to be structure boundaries since arbitrary regions it might be hard to say whether a given edit was inside or outside (since physical position on the diagram has no semantic meaning in LabVIEW, knowing how to group new code would seem to require LV to have AI-like understanding of the purpose and association of new code), but perhaps there is a way to solve this.

 

Going down this road might extricate code reuse from the complicating topic of inheritance and class association. While such association provides many other benefits, I find it occassionally desirable to have a more broad mechanism for code reuse. Something like an arbitrary "copy this code to here, but keep aware of any changes to the original" feature might help encourage code reuse without creating the pain of, "Oh, you'll have to refactor that if you want it to work."

4 Comments
Intaris
Proven Zealot

Aristos,

 

I was essentially getting at something similar in my idea HERE but I have to admit your proposal is much more verbose and intelligently written than mine.

 

I'm giving this Kudos for sure even though the implementation is still a bit sketchy.

Marc Blumentritt
Member

I have a lot of templates, which use Enums (e.g. state machines). Since these Enums are always specific for an application, I cannot place these in some standard library for reuse. These templates are evolving over time. It would be nice, if I could merge the changes of my templates to my specific applications. Therefore many kudos to this great idea!

CLD
Intaris
Proven Zealot

I personally have a (large) set of XControls which all share a common functionality.  Wanting to update the "parent template" makes this a huge job at the moment, which is wha I made my original suggestion.  This would also solve my problem and would be a huge benefit to LV's capabilities if implemented properly.

 

Of course XControls with inheritance would solve my problem also.....

jgcode
Active Participant

Hi AQ

 

Do you see this idea having the following use case:

 

In the State Machine vs State Machine presentation, you mentioned to Justin he could have excluded his structure from Block Diagram Cleanup. The JKI State Machine is compiled in LabVIEW 8.2 and distributed as such. Therefore, it misses out on new features in a later versions of LabVIEW.

 

Could we make use of your idea with some disciplined use of Source Code Control?

 

For example, I have a lot of templates in 8.2 that I want to keep in 8.2. But I love the Linked Tunnels feature of 8.6. I don't want to maintain two templates - but at the moment that is the only option I have if I want a Linked Tunnels template and the same 8.2 template. If I make a change to my 8.2 template I also have to make it to my 8.6 template - this is not ideal.

 

If I could branch the 8.2 template and build on top of that in 8.6 or later versions to add new features and be able to merge changes from my 8.2 template to future versions - that would be great.

 

Does you idea cater to this?

Could this work like this between versions (forwards only of course) - thoughts?

 

Cheers

 

-JG

Certified LabVIEW Architect * LabVIEW Champion