06-27-2017 11:56 AM
Hello,
this is a question more about LabVIEW styling and what is proper. I am refactoring code of a state machine and one of the states has a lot of loops in it. A lot of True/False states with stacked sequence structures nested in each other. It looked really messy, so I've started to clean it up by making bigger loops and structures into SubVIs. I feel iffy about this because these SubVIs will only be used once in the entire project and I am only making them to make the front panel cleaner and easier to follow. Is this stylistically alright, or is it a bad habit to overuse SubVIs like this?
06-27-2017 12:02 PM
06-27-2017 12:03 PM
Provided your;
VI name is descriptive
Icon reflects what the sub-VI does
Sub-VI documentation is good
Do it!
When you have trouble at a future date and you know what state the app is currently in, you will be able to go quickly to the associated code either by opening it from the project or from the VI Hierarchy screen.
Just my 2 cents,
Ben
PS Assuming there are no controls, locals, etc in that code.
Ben
06-27-2017 12:27 PM
Just make sure that enforcing execution order through creating subVIs isn't going to eliminate race issues. Sounds weird, right? But maybe the code was depending on a race condition to work correctly, and inadvertently resolving the race condition breaks the application.
Otherwise, this is sound practice. One reason for subVIs is for code reuse, but another big reason is to break up code into meaningful pieces.