altenbach
2007-02-19 07:10:08 UTC
I am sure everyone with even casual familiarity of LabVIEW has run across older (or newer) code that is just peppered with ...
Stacked Sequences from Hell.
Stacked sequences (especially the one's containing sequence locals) are the hallmarks of confusing, unreadable and unmaintainable code. Data flows in all directions (mostly right-to-left), a large percentage of code is hidden at any given time, and it is almost impossible to debug and follow what going on. Often there is clear data dependency (or execution order does not matter), so the sequence serves no purpose. Better programmers don't use stacked sequences at all and even keep flat sequences at a minimum.
Here is an example:
<img src="Loading Image...">
Since the code seems to work "sort of", and trying to rewire things manually will probably lead to accidental errors, we have no choice than to leave things in place...
.. or do we??? :o
If we try to right-click on the sequence, we can only remove individual frames, breaking everything in the process. No go! A dead end! Sigh! :(
<img src="Loading Image...">
But let's not give up just now.... We can easily convert the stacked sequence to a flat sequence, so lets do that as a first step:
<img src="Loading Image...">
At this point, we can remove the flat sequence and all connections remain in place. Now we can just cleanup the elements and wires and everything look much better. Ahhh!!! :)
<img src="Loading Image...">
In summary:
An easy two-step procedure allows us to exterminate unnecessary stacked sequences without any danger of breaking the code. This method should lower the fear to remove these monstrosities. :) Try it today!
This is a Community Nugget. If you want to contribute, please sign up here: <a href="http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=3379#M3379" target="_blank">http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=3379#M3379</a>
Message Edited by altenbach on 02-18-2007 10:43 PM
SeqToFlat.gif:
http://forums.ni.com/attachments/ni/170/230714/1/SeqToFlat.gif
SeqStackedA.gif:
http://forums.ni.com/attachments/ni/170/230714/2/SeqStackedA.gif
CannotRemove.gif:
http://forums.ni.com/attachments/ni/170/230714/3/CannotRemove.gif
Stacked Sequences from Hell.
Stacked sequences (especially the one's containing sequence locals) are the hallmarks of confusing, unreadable and unmaintainable code. Data flows in all directions (mostly right-to-left), a large percentage of code is hidden at any given time, and it is almost impossible to debug and follow what going on. Often there is clear data dependency (or execution order does not matter), so the sequence serves no purpose. Better programmers don't use stacked sequences at all and even keep flat sequences at a minimum.
Here is an example:
<img src="Loading Image...">
Since the code seems to work "sort of", and trying to rewire things manually will probably lead to accidental errors, we have no choice than to leave things in place...
.. or do we??? :o
If we try to right-click on the sequence, we can only remove individual frames, breaking everything in the process. No go! A dead end! Sigh! :(
<img src="Loading Image...">
But let's not give up just now.... We can easily convert the stacked sequence to a flat sequence, so lets do that as a first step:
<img src="Loading Image...">
At this point, we can remove the flat sequence and all connections remain in place. Now we can just cleanup the elements and wires and everything look much better. Ahhh!!! :)
<img src="Loading Image...">
In summary:
An easy two-step procedure allows us to exterminate unnecessary stacked sequences without any danger of breaking the code. This method should lower the fear to remove these monstrosities. :) Try it today!
This is a Community Nugget. If you want to contribute, please sign up here: <a href="http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=3379#M3379" target="_blank">http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=3379#M3379</a>
Message Edited by altenbach on 02-18-2007 10:43 PM
SeqToFlat.gif:
http://forums.ni.com/attachments/ni/170/230714/1/SeqToFlat.gif
SeqStackedA.gif:
http://forums.ni.com/attachments/ni/170/230714/2/SeqStackedA.gif
CannotRemove.gif:
http://forums.ni.com/attachments/ni/170/230714/3/CannotRemove.gif