The Sequence StructureFlat or Stacked


Determining the execution order of a program by arranging its elements in a certain sequence is called control flow. Visual Basic, C, and most other procedural programming languages have inherent control flow because statements execute in the order in which they appear in the program. LabVIEW uses the Sequence Structure to obtain control flow within a dataflow framework. A Sequence Structure is an ordered set of frames that execute sequentially. A Sequence Structure executes frame 0, followed by frame 1, then frame 2, until the last frame executes. Only when the last frame completes does data leave the structure.

There are two flavors of Sequence Structure: the Flat Sequence Structure and the Stacked Sequence Structure, shown in Figure 6.43 and Figure 6.44, respectively. These can both be found in the Programming>>Structures subpalette of the Functions palette. The two types of Sequence Structure are almost identical, having frames that look like frames of a film. The difference is that the frames of a Flat Sequence Structure are organized sequentially side-by-side and the frames of a Stacked Sequence Structure are organized sequentially in a stack, appearing similar to a Case Structure.

Figure 6.43. Flat Sequence Structure


Figure 6.44. Stacked Sequence Structure


Regardless of appearance, either type of Sequence Structure (Flat or Stacked) executes code exactly in the same manner. In fact, you can easily convert one into the other by selecting from its pop-up menu, Replace with Stacked Sequence (to convert from Flat to Stacked) or Replace>>Replace with Flat Sequence (to convert from Stacked to Flat).

Don't let the size advantage of the Stacked Sequence Structure lure you into thinking that it is a better choice than the Flat Sequence Structure. As we will soon find out, the use of Stacked Sequence Structures can lead to many negative side effects.


Stacked Sequence Structures and Sequence Locals Are Evil

OK, the title of this section is pretty harsh. Sequence Locals aren't really evilthey have no minds of their own. However, we want to be sure that you know to avoid using them or you may find yourself heading down the dark and dangerous path toward a VI full of spaghetti code. Let's take a look at the Stacked Sequence Structure and Sequence Locals, and then we will look at an example that shows why we should avoid them.

Like the Case Structure, the Stacked Sequence Structure has only one frame visible at a timeyou must click the arrows at the top of the structure to see other frames, or you can click on the top display for a listing of existing frames, or pop up on the structure border and choose Show Frame . . . . When you first drop a Sequence Structure on the block diagram, it has only one frame; thus, it has no arrows or numbers at the top of the structure to designate which frame is showing. Create new frames by popping up on the structure border and selecting Add Frame After or Add Frame Before.

There are some very important reasons why the Flat Sequence Structure is a better choice than the Stacked Sequence Structure:

  • Because all the frames of a Flat Sequence Structure are visible, you can see all of your code at once.

    Figure 6.45. Sequence Local cannot be used.

    Figure 6.46. Sequence Local is a data sink, in the frame that initializes its value.

    Figure 6.47. Sequence Local is a data source, after it has been initialized; it can be wired to an indicator (a data sink).

    Figure 6.48. Sequence Local is a data source, after it has been initialized; you cannot wire an input value (another source) to it.

  • Data is passed between frames of a Flat Sequence Structure using tunnels, rather than Sequence Locals (which are evil).

Sequence Locals are evil because

  • They force you to break the left-to-right convention of data-flow programming.

  • You cannot easily see which frame initializes a Sequence Local.

  • They tend to multiplyyou will generally need more Sequence Locals in a Stacked Sequence Structure than tunnels in a Flat Sequence Structure with the same frames of code.

Figure 6.49 and Figure 6.50 show the dramatic difference between the Flat Sequence Structure and the Stacked Sequence Structure. It is easy to see the difference in readability.

Figure 6.49. A simple example using a Flat Sequence Structureclean!


Figure 6.50. A Stacked Sequence equivalent of our Flat Sequence Structure exampleyuck!





LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net