At a recent JKI Team “LabVIEW Lunch” (where the team gets together to eat and talk shop), we were discussing JKI State Machine Best Practices. Note: the JKI State Machine, an easy-to-use yet powerful state machine template we created to help LabVIEW developers write code faster.
After some brainstorming and discussion we took a vote on what was the most important best practice to follow. It was unanimous...
The #1 Best Practice: Don’t hide your state strings in SubVIs -- keep them on the block diagram of the JKI State Machine.
Here are a couple screenshots to show what we mean:
Good Practice: Keeping the state string on the block diagram.
Bad Practice: Putting the state string into a subVI
By keeping the state strings on the block diagram of the JKI State Machine (rather than buried deep inside subVIs) we gain a couple key benefits:
Benefit #1) The readability of your code improves -- you don't have to navigate into subVIs to figure out the logical flow of the JKI State Machine. This allows you to code more quickly, which is one of the key goals of the JKI State Machine. Putting code into subVIs just slows down code readability and maintenance.
Benefit #2) You can use LabVIEW’s built-in “Find” dialog -- you can search for instances of a specific state string on the block diagram of the VI containing the JKI State Machine.
For example, open the Find dialog by selecting <Ctrl+F> and search for a state string like "UI: Initialize". Be sure to set the Search Scope to the VI containing the JKI State Machine.
Clicking "Find" will then locate all instances of "UI: Initialize" in the block diagram of your VI.
This ability to Find (and Replace) the state strings in your VI’s block diagram is a hugely powerful tool and it doesn't work nearly as well if you start putting your state strings into subVIs.
Benefit #3) The coupling is loosened between the state transition logic and the rest of the application code -- the JKI State Machine logic/flow stays loosely coupled from all the other code/VIs in the software. This means that changes to one VI don’t inadvertently change the functionality of code in other place.
Bottom line: Take advantage of these great benefits to keeping your state strings on the block diagram of the JKI State Machine (and please, don’t hide your state strings in subVIs) :)
We'd like to hear about your best practices for using the JKI State Machine. Please post comments and suggestions, below. And, if you have ideas for making the JKI State Machine better, please post them to the JKI State Machine GitHub Issue Tracker.
And a note from our sponsor: At JKI we use the JKI State Machine every day to help our our clients get their innovative high-tech products and technology to market fast. If you need help taking your system software to the next level or reach an important milestone, contact us to learn more about our services.