Tuesday, March 3, 2009

A Good Use for Block Diagram Cleanup

One of the big new features of LabVIEW 8.6 is Block Diagram Cleanup, a way to instantly rearrange block diagram contents to make them look "better". In fact, I demoed this feature briefly during my NI Week 2008 keynote appearance. In practice, however, I find that I don't really use the feature all that much. Keeping the diagram clean as I write code has been an integral part of the way I do my job for the past several years, and honestly, if I run Block Diagram Cleanup on my clean code, it makes it considerably less clean. I know many other advanced LabVIEW developers who feel the same way.

Lately though, I have discovered a perfectly valid niche use case for this feature. One of the great things about LabVIEW is how easy it is to write "throw away" code...you know, that simple prototype VI that you write just to test an idea, or that debugging VI that helps you quickly unit test something you're working on...or even the VI where you just drop a single function and wire a few things in to double-check that it works the way you expect (I do this with Match Pattern about once every few months). Well, I tend to write throw away code very quickly, with no regard for "cleanliness". It's these throw away VIs that are the perfect candidates for Block Diagram Cleanup...with a single Ctrl-U, my code becomes considerably more clean than it was before, when I was slinging objects left and right with Quick Drop and reckless abandon. And even though it's throw away code, it's still easier to understand and modify (before I throw it away) if it's clean.

Here's an example "before and after" of one of these situations. In this case, I wanted a VI that displayed every single value in my LabVIEW Class data...in this case, there were several subclasses that contained arrays, so a simple probe wouldn't let me see multiple array elements at once...so I basically wrote a huge "probe" VI that displayed a bunch of these arrays, with several elements expanded. This VI was purely for debugging, and would be of limited utility once I got all my class data straightened out...in other words, it was a "throw away" VI. So I slopped it together, then I cleaned it up. Although not perfect, the cleaned up version is much easier to understand (sorry for all the Wite-Out...these classes pertain to features that have yet to be released):

Before:


After:


I understand that this might be a pretty limited use case, but who knows...maybe I should get my feet wet with the feature now, in the event that it gets a lot better in a future LabVIEW version?

9 comments:

  1. I totally agree that I don't find Clean Up as useful as it should be. Part of the reason is that it's trying to optimize the whole diagram, it's too complex for the routine to handle. It will be a powerful feature if we can select just part of the diagram and Clean Up just those parts.

    ReplyDelete
  2. Dan: It would not be unreasonable to see something like a partial diagram cleanup in a future LabVIEW version.

    ReplyDelete
  3. Like you, I tend to frequently create throw-away VIs to check the functionality of code snippets.

    While we're talking about productivity with throw-away VIs, imagine being able to right click any function or subVI (e.g. Match Pattern) and select "Create Controls & Indicators" (or just Create Controls or Create Indicators).

    In case someone else thinks it would be nice, I've made the product suggestion. (Feel free to do the same!)

    -Jason

    ReplyDelete
  4. Yup, if there's one LV node I will *always* wire up to test out, every single time, after all these years, it's Match Pattern. Ok, two. Match Regular Expression.

    Dave

    ReplyDelete
  5. I agree with Dan. It would be really nice to be able to clean up a selected part of your vi. Would definitely use that all the time.

    ReplyDelete
  6. I totally agree, partial clean up would be cool! Maybe someone can write a script..?!

    ReplyDelete
  7. No need to write a script...just wait another couple of weeks. ;)

    ReplyDelete
    Replies
    1. Hmmm ... well ... so much for "another couple of weeks".

      Still waiting ...

      Delete
    2. What are you waiting for...somebody to buy you a copy of LabVIEW 2010? Because that was the first version of LabVIEW that included partial diagram cleanup. ;)

      Delete