LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anything wrong with sequence structures?

Hello,

 

I have a very general question regarding coding.  I've done a few VIs where I try and force myself to stay within the confines of my computer screen... and I use stacked sequence structure to do this... the end result, to me, looks a lot cleaner than when I have code all over the place... so I usually set my 1st page in the sequence to initialize stuff, then the 2nd page with my main while loop (and within the while loop there will be another staacked sequence with several pages) and then the next page will have anything I need to do after the main while loop is done.

 

My question, is this good coding practice? is there anything wrong with working this way?  I've heard there's the drawback of your code is hidden... but I don't mind that, it's organized well enough.

 

opinions?

0 Kudos
Message 1 of 14
(4,043 Views)
The fact that the stacked sequence structure is part of LabVIEW tells me that there's nothing wrong with them, but I'd die before I used one!  You can accomplish much more with a state machine and avoid being "one of those" programmers.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 14
(4,035 Views)

By that logic the fact that GOTO is part of BASIC and C means there's nothing wrong with that either! The bigger point is that they are totally unnecessary. If you write your code correctly there is no reason to use them. They offer no reusability, complicate wiring, negatively impact readability, scalability and maintainability - and yes hide code. They do not have even one positive attribute or effect.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 3 of 14
(4,021 Views)

I was thrown in to LabVIEW by maintaining code with sequence structures. I guess one sequence structure is okay.

 

Sequence structures nested within other sequence structures get a little hard to follow.

 

I guess that's how they taught beginning LabVIEW users 15 years ago.

 

Sequence structures nested within other sequence structures start to iritate you.

 

Sequence structures nested within other sequence structures nested within other sequence structures start to realy iritate you.

 

Sequence structures nested within other sequence stuctures nested within other sequence structures nested within sequence structures start you to saying that you don't like LabVIEW.

 

Sequence structures nested....... to infininium ... make you hate LabVIEW, especially when you have a postage size space to try to make a change.

0 Kudos
Message 4 of 14
(4,009 Views)

gchristi1 wrote:

Sequence structures nested....... to infininium ... make you hate LabVIEW, especially when you have a postage size space to try to make a change.


Yes but you get such a neat "Time Tunnel" effect when you move the selection tool back and forth across deeply nested structures.  Smiley Very Happy

 

Mike...

 

PS: "Time Tunnel" was a scifi program from the 60s with very cheesy special effects but a very cool tunnel. Admitedly not as cool as the computer on the "Seaview" but still very nice.

PPS: The "Seaview" was a submarine with 12ft ceilings from "Voyage to the Bottom of the Sea" (movie and TV show).


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 5 of 14
(4,003 Views)

ok... I like state machines too, but I'm not talking about state machines here.  And, the fact that they are part of LabVIEW doesn't mean there's nothing wrong with them.


 

The reason I ask this is cause I remember from reading some LabVIEW book or in conversation or somewhere... to avoid stacked sequences, but lately I've been able to simplify a huge while loop to fit on my computer screen by having a stacked sequence in the while loop (and yes maybe a couple more stacked sequences within that)... so I can't remember why that warning to avoid stacked sequences was given if it's:

 

they offer no reusability            < I'm not sure what you mean here.... reusability? 

complicate wiring                     <

negatively impact readability    <

scalability and maintainability   < I'm not sure what you mean by scalability here...

hide code                                  <

 

It seems like most of these reasons not to use them are dependant of the programmer and whether or not they can make clean code with it... but not really any drawbacks with functionality... so, unless I'm missing something it sounds like there's nothing wrong with them as long as you use them in such a way that your wiring doesn't get complicated, and your code is readable....

 

Thanks for your posts!

0 Kudos
Message 6 of 14
(3,998 Views)

Reusability means just what it says: the ability to reuse pieces of your code. If you have a particular function implemented as a subVI (the correct way to do it) you can reuse that VI anytime you need the same functionality. If the functionality is in one or two frames of a sequence, you can't.

Scalability is the ability to add more functionality of the same basic type without major structural changes to your program. Say you have a VI that can acquire data from 5 thermocouples and you want to expand it to reading 20 thermocouples.

Maintainability is the ability to add functionality of a different type without major structural changes to your program. Say you have that same VI that can acquire data from 5 thermocouples but now you want to expand it to read 5 strain gauges.

 

Your last point is sort of like saying its ok to play russian roulette as long as you don't get shot. If you use sequences your code will have complicated wiring and your code will be unreadable - and with this it's not a 1 in 6 chance, its guaranteed.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 7 of 14
(3,995 Views)

Let's go to the benefits of a state machine.

 

A state machine has meaningful names in the cases: "Init, Aquire, Present, Shutdown" and not "0,1,2,3".

That's a much better documentation...

 

One of the points I hate on stacked sequences is, that wires will have to go left to move data to the next stage. That takes effort doing the cosmetics. The shift registers of a state machine take much less time to maintain...

 

If you at one stage realize, that you not want to run it seqential, but directly jump to the shutdown code on errors or repeat the measurement upon user request, you get headaches with your nested loops and sequences. A state machie adapts to these needs by desgn. That's why I use state machines even for simple code that hasonly the Init, Idle and Shutdown stage.

 

Here is one more case of reusability: Not only SubVis can be placed on several locations in the code, but states can be called from multiple locations. Consider a simple Save and Save as functionality. Save would go to state 'Save' and Save As would display a File Dialog and then go to state 'Save'.

 

Felix

0 Kudos
Message 8 of 14
(3,973 Views)

jcarmody wrote:
The fact that the stacked sequence structure is part of LabVIEW tells me that there's nothing wrong with them, but I'd die before I used one!  You can accomplish much more with a state machine and avoid being "one of those" programmers.

 

Wrong is in italics. 

 

I was unclear and subsequently misunderstood; my reputation is shot.  Rats.  Smiley Sad  Good thing I'm not popular! Smiley Very Happy

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 9 of 14
(3,964 Views)

This debate has fascinated me for a while.

 

About sequence structures in general, stacked and flat, I have heard what sounded to me like a suggestion for a programming trick: run error wires through things to dictate their execution order, and you don't have to use sequence structures. I bristled at this because it sounded like a trick, our instructor called it a trick when he introduced it, it does not make clear the programmer's intent to dictate order (not just to collect errors), and there is an explicit mechanism, the sequence structure, specifically for doing this.

 

In the last such debate people explained this further until I caught on. Now I would say that wiring does dictate execution order, and error wiring is important (in some ways more important than wiring the data you care about), and if wiring dictates all the time sequencing you care about, there is no need to introduce structures. If you worry about conveying programmer intent, you can always opt for a note, instead.

 

They say stacked sequences are bad because they hide all but one frame of the code. I don't accept this as the final word, because it applies equally to case structures, and therefore to state machines while we're at it. Showing things versus hiding them is always a judgement call. Yesterday I went through about 50 vi's clicking Hide Full Names on all the Unbundle By Names. Much neater. On the other hand, in Blume's absolutely excellent LabVIEW Style Book, he recommends turning off the dots at wire intersections that are connected, saying it looks neater. Unless you can make wires that cross without connecting show little halfcircles on one wire jumping over the other, though, I think they are absolutely necessary to make clear what is connected. He says you can always click on a wire to see if the other one is connected to it. I think that's like clicking on each word to see what it says when you are reading - way too obtrusive. The diagram would be even neater if we got rid of the wires. Well, OK, now I am ranting, but I still see these things as judgements and not simple rules.

 

Yes, you can replace a stacked sequence with a state machine. That is not a reason to never use stacked sequences, any more than the fact you might be able to replace a state machine with a stacked sequence is a reason to never use state machines.

 

Now, I have heard ugly complaints about sequence variables in particular, and I have not even tried them. My only stacked sequences do things like writing a dozen different phrases sequentially into a string indicator with a different display time on each. These stacked sequences have frames that all look pretty similar and don't have much wiring going in or out, maybe none at all.

 

I do use flat sequences somewhat often, generally for the purpose of sequencing things that get inconvenient or cluttered if I overuse wiring to do it. But I use them less than before.

 

The way you describe your use doesn't necessarily sound bad to me, though when you say you struggle to fit into a screen and the stacked sequence saves this, I wonder if it would be better to break out more blocks of your code into subvi's. There are times, though, where there are so many things logically interconnected and interdependent, where they do not reasonably organize into discrete sub tasks, such that breaking blocks of code out into subvi's would feel worse than stacked sequences or multiscreen block diagrams.

 

My 2 cents, anyway.

0 Kudos
Message 10 of 14
(3,945 Views)