{"id":3948,"date":"2014-09-15T10:30:08","date_gmt":"2014-09-15T17:30:08","guid":{"rendered":"http:\/\/www.themoehrings.com\/?p=3948"},"modified":"2026-02-26T10:59:26","modified_gmt":"2026-02-26T16:59:26","slug":"ode-to-stacked-sequence-structures","status":"publish","type":"post","link":"https:\/\/www.themoehrings.com\/index.php\/2014\/09\/ode-to-stacked-sequence-structures","title":{"rendered":"Ode to Stacked Sequence Structures"},"content":{"rendered":"<p><strong>Introduction and Disclaimer<\/strong><\/p>\n<p>LabVIEW 2014 has removed the Stacked Sequence Structure (SSS) from the palettes, and my guess is in just a few years the phrase \u201cStacked Sequence Structure\u201d will be totally gone from our vocabulary.\u00a0 Before that happens, I would like to officially state my position on SSSs.\u00a0 I realize that by doing this I risk my reputation in the LabVIEW community, so let me make it absolutely clear right now that:<\/p>\n<ul>\n<li>I agree with NI\u2019s decision to remove the SSS from the palette,<\/li>\n<li>I agree that SSSs can contribute to less readable and less manageable code<\/li>\n<li>I agree with NI\u2019s decision not to allocate resources to improve SSSs by adding a shift register as suggested by <a href=\"https:\/\/forums.ni.com\/t5\/LabVIEW-Idea-Exchange\/Stacked-Sequence\/idi-p\/918243\">this idea<\/a>, but only on the basis that NI has to prioritize limited resources, not on the principle that it would be a bad addition to the language.<\/li>\n<\/ul>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Background<\/strong><\/p>\n<p>Sequence structures serve an important role in LabVIEW, to enforce execution order when there is no directly corresponding data dependency.\u00a0 Sequence Structures, either Stacked or Flat, are the most simple way to achieve this.\u00a0 The primary difference between Stacked Sequences and Flat Sequences is that SSSs make the language more 3-dimensional, while Flat Sequence Structures (FSSs) give preference to reader-friendly, 2-dimensional layout.<\/p>\n<p>Readability is very important, but LabVIEW is still an inherently 3D language, removing SSSs doesn&#8217;t change that fact.\u00a0 Case Structures, Event Structures, Conditional Diagram Structures, subVIs, the fact that objects on the diagram have a z-order that needs to be managed, all of these contribute to the 3D nature of graphical programming.\u00a0 Therefore I think SSSs have been unfairly villainized as the cause of bad code in the same way that global variables have been villainized.\u00a0 There is a time and place where these programming constructs can be used responsibly.\u00a0 (Here\u2019s a <a href=\"http:\/\/labviewartisan.blogspot.com\/2010\/06\/i-like-global-variables.html\">great blog<\/a> written by Darren Nattinger on valid uses of global variables.\u00a0 I wish I written that blog, as I have long secretly felt the same way but dared not speak in defense of the reviled global variables.)<\/p>\n<p>I agree that SSSs can be overused, and truthfully I don&#8217;t use sequence structures of either type very often, stacked or flat.\u00a0 But when I do, I&#8217;d say it\u2019s probably an even 50\/50 on whether I choose stacked or flat, given the specific situation.<\/p>\n<p>Before I describe what I believe are valid uses for SSSs, let me first give further credence that Stacked Structures have been villainized.\u00a0 Ever seen code like this?<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/SSS-obscured.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4093\" src=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/SSS-obscured.png?resize=423%2C270&#038;ssl=1\" alt=\"SSS obscured\" width=\"423\" height=\"270\" srcset=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/SSS-obscured.png?w=423&amp;ssl=1 423w, https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/SSS-obscured.png?resize=300%2C191&amp;ssl=1 300w\" sizes=\"auto, (max-width: 423px) 100vw, 423px\" \/><\/a><\/p>\n<p>I&#8217;ve seen code that uses this for loop + case structure combination specifically as a means to avoid using SSSs.\u00a0 Sorry people, what we have here is a convoluted SSS, you\u2019ve just disguised it.\u00a0 The compiled code this creates is less efficient, it\u2019s less intuitive to the reader, and the writer has to remember that the valid frames are 0 through 6, not 7.\u00a0 Should Default be its own case?\u00a0 Does it matter?\u00a0 What should Default do if it\u2019s reached?<\/p>\n<p>Yes it&#8217;s true that this tricked out SSS does provide two potential features that the stock SSS does not provide: a linear shift register, and the option to abort the sequence early using a conditional stop terminal.\u00a0 And as I said earlier, I think those would be great additions to the SSS if resources were not limited.\u00a0 What I don\u2019t understand is why the comments posted on this <a href=\"http:\/\/labviewartisan.blogspot.com\/2010\/06\/i-like-global-variables.html\">idea<\/a> are so visceral, so negative, like the author just asked for a gold plated gun that he, or other innocent LabVIEW newbies, might use to shoot themselves.\u00a0 One of the comments on the post states specifically that LabVIEW R&amp;D has rejected this idea because it would make Stacked Sequences more desirable to use, thereby encouraging bad practice.\u00a0 Yes, using State Machines is a better way to code, but it still hides code (3D), it requires many more clicks to create, and it may be a more complex solution than what a specific situation may require.<\/p>\n<p>I do agree with critics that Sequence Locals are an abomination because they require the use of backward wires and passing data from frame to frame to frame is obnoxious, especially if you need to support modifying the value in multiple frames.\u00a0 I would be fully in favor of removing Sequence Locals after adding shift registers to the SSS.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Valid Uses for Stacked Sequence Structures<\/strong><\/p>\n<p>Here are the uses cases where I think SSSs are totally acceptable:<\/p>\n<ul>\n<li><strong>Timing Metrics<\/strong>. The railroad-tie approach to getting a timestamp before and after an operation requires too much screen space and adds no value to understanding the code that\u2019s really of interest. It requires you to elongate your diagram for the sake of adding code that\u2019s likely temporary.\u00a0 In my opinion, I\u2019d rather see the SSS implementation, particularly if it is being added to an existing diagram.<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Timing-Metrics.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3949\" src=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Timing-Metrics-300x281.png?resize=300%2C281&#038;ssl=1\" alt=\"Timing Metrics\" width=\"300\" height=\"281\" srcset=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Timing-Metrics.png?resize=300%2C281&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Timing-Metrics.png?w=430&amp;ssl=1 430w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> I can very easily infer what\u2019s happening in frame 0 and 2, and dataflow is preserved.\u00a0 As long as frame 1 is saved as the visible frame, the reader can focus on the code of interest.<\/li>\n<li><strong>Debug Code<\/strong>. Debug code, occurring before or after your code of interest, further detracts from the readability of your code.\u00a0 Debug code may start out temporary and over time become quasi-permanent if a sporadic issue is never fully resolved.\u00a0 But in either case, I don\u2019t want the reader to be distracted from the main intent of the diagram.\u00a0 Good candidates for debug code in a SSS are non-impactful, such as writing print statements to a log file or DETT trace, or adding information to an error cluster.\u00a0 However, operations with more noticeable impact in terms of execution speed or operator interaction should not be placed in a SSS.\u00a0 Things like sending emails or opening dialogs need to obvious to the reader so they can be periodically re-evaluated, and so the reader knows this code has major limitations on its ability to be reused directly.<\/li>\n<li><strong>Setup and Teardown Code<\/strong>. SSSs are also convenient for simple Setup\/Teardown code that must be run before or after the code of interest.\u00a0 I find this particularly useful when inheriting code that already makes use of local variables, global variables, or Action Engines (FGVs with logic).\u00a0 Rarely do I advocate for the cost or risk associated with refactoring legacy code to eliminate the use of these constructs.\u00a0 Refactoring might make sense if you are planning to make major updates and you know there are many more years of life remaining on this software or system.\u00a0 However, in many cases, simple updates or fixes can be made with only minor modifications to the existing code, which avoids the cost of refactoring and more importantly avoids introducing significant new risk into your system.\u00a0 A SSS can easily wrap around the code of interest, and then frames can be added before or after to perform the necessary setup or teardown such as initializing variables or calling specific options on an Action Engine.\u00a0 This may be the least invasive way to update legacy code.<\/li>\n<\/ul>\n<p>So there you have it, three use cases for Stacked Sequence Structures that I think are totally legit, when used in moderation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>What is a Structure?<\/strong><\/p>\n<p>On a more philosophical level, there\u2019s another thing about FSSs that bother me, a little\u2026\u00a0 For all other Structures, NONE of the tunnels output data until ALL of the sub-diagrams have completed.\u00a0 This is not true with FSSs, and I think this is a distinction between Flat and Stacked structures that many people have not considered.\u00a0 Output tunnels on Flat structures output data on a per-frame basis.\u00a0 In fact, it\u2019s possible to have data leave the structure in one frame, skip several frames, and reenter the structure in a later frame.\u00a0 This blurs the definition in my mind of what a structure is.\u00a0 A structure should start executing at one point in time (reading all inputs), and stop executing at a later point in time (writing all outputs).\u00a0 Not true with the FSS.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Comparison-of-SSS-and-FSS-behavior.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3950\" src=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Comparison-of-SSS-and-FSS-behavior.png?resize=742%2C719&#038;ssl=1\" alt=\"Comparison of SSS and FSS behavior\" width=\"742\" height=\"719\" srcset=\"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Comparison-of-SSS-and-FSS-behavior.png?w=742&amp;ssl=1 742w, https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2014\/09\/Comparison-of-SSS-and-FSS-behavior.png?resize=300%2C290&amp;ssl=1 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/a><\/p>\n<p>I agree with the implementation NI has taken, it is much more flexible and fits the dataflow paradigm better than the restrictive definition of Structure that I have provided above.\u00a0 I suspect that I do not have the correct technical definition of a Structure, but it has served me well thus far.\u00a0 The exception I have to make to my mental model of a Structure is that each frame of a FSS is really like its own single-frame sequence structure, each frame acting as its own structure, strung together and made sequential by the compiler.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>For the reasons I have stated here, I think removing the SSS altogether would be a mistake that would fall into the category of &#8220;we know what&#8217;s best for you&#8221;.\u00a0 I don\u2019t like when NI makes decisions for my \u201cprotection\u201d when it means being more restrictive or taking away features. \u00a0Fortunately SSSs haven\u2019t been removed completely, and I&#8217;m quite satisfied with making FSSs the default as they&#8217;ve done in 2014.\u00a0 Converting this to a SSS only takes one extra click, and considering that in prior versions you start out with a single frame, Stacked or Flat, it\u2019s really a wash.\u00a0 I think NI has made a good decision to remove the SSS from the Structures palette in LabVIEW 2014, I just hope they don\u2019t completely remove it from future versions of LabVIEW.<\/p>\n<p>(No code was harmed by SSSs in the making of this blog.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction and Disclaimer LabVIEW 2014 has removed the Stacked Sequence Structure (SSS) from the palettes, and my guess is in just a few years the phrase \u201cStacked Sequence Structure\u201d will be totally gone from our vocabulary.\u00a0 Before that happens, I would like to officially state my position on SSSs.\u00a0 I realize that by doing this&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[15],"tags":[],"class_list":["post-3948","post","type-post","status-publish","format-standard","hentry","category-labview","wpcat-15-id"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p504YJ-11G","jetpack-related-posts":[{"id":1684,"url":"https:\/\/www.themoehrings.com\/index.php\/2011\/10\/accessing-objects-by-reference-in-labvoop","url_meta":{"origin":3948,"position":0},"title":"Accessing Objects By Reference in LabVOOP","author":"Nate","date":"October 24, 2011","format":false,"excerpt":"https:\/\/decibel.ni.c...\/docs\/DOC-18320 Motivation for this presentation: At the 2011 CLA Summit, National Instruments asked us what we thought was missing from LabVIEW or what needed to be improved. I already knew NI\u2019s position on this, but my feedback to NI and direct conversation with Stephen Mercer, father of LabVOOP, was that\u2026","rel":"","context":"In &quot;LabVIEW&quot;","block_context":{"text":"LabVIEW","link":"https:\/\/www.themoehrings.com\/index.php\/cat\/labview"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":951,"url":"https:\/\/www.themoehrings.com\/index.php\/2010\/12\/new-blog-category-labview","url_meta":{"origin":3948,"position":1},"title":"New blog category: LabVIEW","author":"Nate","date":"December 15, 2010","format":false,"excerpt":"Future of LabVIEW","rel":"","context":"In &quot;LabVIEW&quot;","block_context":{"text":"LabVIEW","link":"https:\/\/www.themoehrings.com\/index.php\/cat\/labview"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2010\/12\/68a47da47f1a03454aa98e84b3420c5f.jpeg?fit=800%2C200&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2010\/12\/68a47da47f1a03454aa98e84b3420c5f.jpeg?fit=800%2C200&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2010\/12\/68a47da47f1a03454aa98e84b3420c5f.jpeg?fit=800%2C200&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2010\/12\/68a47da47f1a03454aa98e84b3420c5f.jpeg?fit=800%2C200&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":10582,"url":"https:\/\/www.themoehrings.com\/index.php\/2018\/03\/labview-tortoise-or-hare","url_meta":{"origin":3948,"position":2},"title":"LabVIEW &#8211; Tortoise or Hare","author":"Nate","date":"March 4, 2018","format":false,"excerpt":"Attached are the slides presented by Nate Moehring on Sept 19th, 2017 at the Certified LabVIEW Architect Summit on best practices for managing performance risks associated with LabVIEW applications that handle large amounts of data, as well as advanced tips and tricks for writing high performance LabVIEW code. LabVIEW -\u2026","rel":"","context":"In &quot;LabVIEW&quot;","block_context":{"text":"LabVIEW","link":"https:\/\/www.themoehrings.com\/index.php\/cat\/labview"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10578,"url":"https:\/\/www.themoehrings.com\/index.php\/2018\/03\/unit-testing-in-labview","url_meta":{"origin":3948,"position":3},"title":"Unit Testing in LabVIEW","author":"Nate","date":"March 4, 2018","format":false,"excerpt":"Attached are the slides and example project presented by Nate Moehring during the March 1st, 2018 presentation at the LabVIEW Architect Forum on advanced tips and tricks for writing unit tests in LabVIEW.\u00a0 Some justification is provided for unit testing in general, but most of the presentation covers the advanced\u2026","rel":"","context":"In &quot;LabVIEW&quot;","block_context":{"text":"LabVIEW","link":"https:\/\/www.themoehrings.com\/index.php\/cat\/labview"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":954,"url":"https:\/\/www.themoehrings.com\/index.php\/2010\/12\/labview-exceptions-a-paradigm-shift-to-error-handling-in-labview","url_meta":{"origin":3948,"position":4},"title":"LabVIEW Exceptions: a paradigm shift to error handling in LabVIEW","author":"Nate","date":"December 15, 2010","format":false,"excerpt":"This is a presentation I gave to about 40 Certified LabVIEW Architects back in March 2010\u00a0at the\u00a0CLA Summit in Austin, TX.\u00a0 It presents some ideas on ways in which exception handling error techniques that are used in C++ and Java could be incorporated into LabVIEW by National Instruments, and the\u2026","rel":"","context":"In &quot;LabVIEW&quot;","block_context":{"text":"LabVIEW","link":"https:\/\/www.themoehrings.com\/index.php\/cat\/labview"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2719,"url":"https:\/\/www.themoehrings.com\/index.php\/2013\/04\/religious-about-labview","url_meta":{"origin":3948,"position":5},"title":"Religious about LabVIEW","author":"Nate","date":"April 5, 2013","format":false,"excerpt":"I realized this week at the CLA Summit that I am religious about LabVIEW. What does this mean? It means that despite conflicting evidence and statements made by individuals about the strengths and weaknesses of LabVIEW (including key individuals within NI), I have made a choice long ago to have\u2026","rel":"","context":"In &quot;LabVIEW&quot;","block_context":{"text":"LabVIEW","link":"https:\/\/www.themoehrings.com\/index.php\/cat\/labview"},"img":{"alt_text":"CLA Logo","src":"https:\/\/i0.wp.com\/www.themoehrings.com\/wp-content\/uploads\/2010\/09\/LabVIEW_Cert_Arch-4c-300x81.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/posts\/3948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/comments?post=3948"}],"version-history":[{"count":5,"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/posts\/3948\/revisions"}],"predecessor-version":[{"id":35099,"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/posts\/3948\/revisions\/35099"}],"wp:attachment":[{"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/media?parent=3948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/categories?post=3948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.themoehrings.com\/index.php\/wp-json\/wp\/v2\/tags?post=3948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}