LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why are sequences so bad?

In article <506500000008000000C04F0000-1023576873000@exchange.ni.com>,
x@no.email (fairhairedwineboy) wrote:

> OK, Am I the only one who beleives that sequences are OK and even a
> good thing?
>

Hi

I've found this thread very interesting and hope to add a new slant to the
debate.

I'm a non-programmer who uses LV for controlling lab devices. I'm probably
the only person who will ever look at the code I have written. This is
lucky because I make extensive use of sequences. I recognise the
difficulty in following code which is entrenched inside a multi-frame
sequence, but surely this is only a disadvantage if others may have to
pick-up the code later. The process I'm controlling is a sequence of
events so LV sequence structures lend themselves nicely
to the
application.

So don't discount sequences, especially if your application is sequential
in nature. To me it seems bizarre to go down the path of introducing error
handling such that a sequence can flow if that is all you do with the
errors.

Anyway, I'm glad I have learnt something by following this thread i.e. how
to use data flow to control a sequence. I hope I can figure it out when I
try something new with LV and can have a proper comparison to using
sequences.

Thanks for the discussion

Regards

Bill

mailto:wsymonds@clara.co.uk
0 Kudos
Message 11 of 22
(1,520 Views)
wsymonds@clara.co.uk (Bill Symonds) wrote in message news:...
> In article <506500000008000000C04F0000-1023576873000@exchange.ni.com>,
> x@no.email (fairhairedwineboy) wrote:
>
> > OK, Am I the only one who beleives that sequences are OK and even a
> > good thing?
> >
>
> Hi
>
> I've found this thread very interesting and hope to add a new slant to the
> debate.
>
> I'm a non-programmer who uses LV for controlling lab devices. I'm probably
> the only person who will ever look at the code I have written. This is
> lucky because I make extensive use of sequences. I recognise the
> difficulty in following code which is entrenched inside a multi-frame
> sequence, but surely this is only a disadvantag
e if others may have to
> pick-up the code later. The process I'm controlling is a sequence of
> events so LV sequence structures lend themselves nicely to the
> application.
>
> So don't discount sequences, especially if your application is sequential
> in nature. To me it seems bizarre to go down the path of introducing error
> handling such that a sequence can flow if that is all you do with the
> errors.
>
> Anyway, I'm glad I have learnt something by following this thread i.e. how
> to use data flow to control a sequence. I hope I can figure it out when I
> try something new with LV and can have a proper comparison to using
> sequences.

Just don't go overboard. Sequences within sequences is madness. Any
further down that path and abandon all hope.
0 Kudos
Message 14 of 22
(1,520 Views)
First, this is/was thoroughly discussed in the topics sections, at least under "Programming Guidelines..." to some extent. However; I will add my three cents (inflation and cost of living have justified a larger participation on my part...or something like that...)

I have come up with a way of thinking about LabVIEW code that makes a lot more sense of sequences. If you consider that all nodes of a diagram are in fact functions, you begin to see what sequence frames really are. They are the exact equivalent of a subVI, in many ways. The only exception is that LabVIEW handles sequence frames in a special way. Multiple frames are executed in sequence, as if wires were between the frames. This is a convenience that is more of a problem than a solution, in my opinion.

Single frame sequences can act just like a subVI, a case, or any node, they are also useful for forcing dataflow as you can have blank inputs to the sequence that make that sequence dependent upon data from other nodes (functions.)

Now, when you consider all this, a multiple frame sequence becomes a stack of functions. While this is okay to the compiler, it is terrible for reading and understanding programs.

I make it a rule NOT to use multiple frame sequences for ANY code that I release or show to anyone else. I ONLY use them when I need a quick and dirty solution to a problem that would otherwise take a bit longer with subVIs. Even then, I prefer to use multiple sequences (single frames each) instead of multiple frames.

There is a very logical reason for this. First and foremost, multiple sequence frames hide code. Yes, I know that case structures do also, but that is a reasonable exception, because when you are going through the code, you only want to see one case at a time anyway. As such, at no time is any working code hidden with a case structure, as long as the appropriate case is hidden. With multiple frame sequences, code is ALWAYS hidden! This is completely unacceptable for trying to make code readable and easy to understand.
Message 12 of 22
(1,520 Views)
"Labviewguru" wrote in message
news:50650000000500000066860000-1023576873000@exchange.ni.com...
> First, this is/was thoroughly discussed in the topics sections, at
> least under "Programming Guidelines..." to some extent. However; I
> will add my three cents (inflation and cost of living have justified a
> larger participation on my part...or something like that...)
>
> I have come up with a way of thinking about LabVIEW code that makes a
> lot more sense of sequences. If you consider that all nodes of a
> diagram are in fact functions, you begin to see what sequence frames
> really are. They are the exact equivalent of a subVI, in many ways.
> The only exception is that LabVIEW handles sequence frames in a
> special way. Multiple frames are executed in sequence, as if wires
> were between the frames. This is a convenience that is more of a
> problem than a solution, in my opinion.
>
> Single frame sequences can act just like a subVI, a case, or any node,
> they are also useful for forcing dataflow as you can have blank inputs
> to the sequence that make that sequence dependent upon data from other
> nodes (functions.)
>
> Now, when you consider all this, a multiple frame sequence becomes a
> stack of functions. While this is okay to the compiler, it is
> terrible for reading and understanding programs.
>
> I make it a rule NOT to use multiple frame sequences for ANY code that
> I release or show to anyone else. I ONLY use them when I need a quick
> and dirty solution to a problem that would otherwise take a bit longer
> with subVIs. Even then, I prefer to use multiple sequences (single
> frames each) instead of multiple frames.
>
> There is a very logical reason for this. First and foremost, multiple
> sequence frames hide code. Yes, I know that case structures do also,
> but that is a reasonable exception, because when you are going through
> the code, you only want to see one case at a time anyway. As such, at
> no time is any working code hidden with a case structure, as long as
> the appropriate case is hidden. With multiple frame sequences, code
> is ALWAYS hidden! This is completely unacceptable for trying to make
> code readable and easy to understand.

I can see your point and will consider creating subvis as an improvement on
sequences. But I still think sequences are far more readable than a diagram
that goes beyond the edges of the monitor.
0 Kudos
Message 13 of 22
(1,520 Views)
I'm sorry. I simply do not agree that sequences are necesarily that hard to follow and understand. I have troubleshot lots of code with sequences and do not find them any more difficult than those with tons of subvis.
Do not misunderstand, I like subvi and use them extensively. However, A blanket policy that sequences are bad - no way - use them if you like and don't waste a lot of time wondering if you should or shouldn't.
0 Kudos
Message 15 of 22
(1,520 Views)
I stopped using sequences when I was developing what turned out to be a dynamic and scalable application, that I didn't know was dynamic and scaleable at the time. It was a 2-3mb program (one diagram! - must be a record...no, wait, I worked on one that was 6!) in and of itself. It had about 200 outer frames, with several inner embedded sequences of up to 70 frames each. I had several dozen local variables (after I figured out what hell using sequence locals was) and was a complete waste of my time, and disk space. I rethought the entire project (this was my first big LabVIEW program, started 4 weeks after learning LabVIEW) and reprogrammed it. Instead of a single 2Mb program, I ended up with a hierarchy of about 20 or so subVIs (a lot of the code in the sequences was reusable) that only took about 250k!!!! This new version was much easier to read, to write, to understand, to modify, to scale, and just plain neater.

One thing you must take into consideration about writing your code. It really doesn't matter how easily YOU can read the code. What matters is how easily someone else can. The general consensus is that sequences are a pain in the butt. However; if noone is ever going to look at your code, then be my guest. But, one thing to consider: will you be able to understand your code a year later, two years later, etc.

If you think of a sequence frame, as it should be, as a function, then creating a function solely on a diagram is a bad idea. Sure, its a bit more work to create a subVI, or a series of subVIs instead of a sequence (and then put the related subVIs into a higher subVI as a single subVI on the main diagram, in place of the sequence structure). But the rewards are incredible. You have reusable code. You have flexible code. You have a central repository for this code. Your code is scaleable. You have automated documentation for your code.

There is no blanket policy that says that sequences are bad, otherwise, they wouldn't exist (although I have requested NI to remove multiple frame capabilities of sequence structures). But the general consensus is that sequences hide code, and make reading the code a big pain in the butt. What is often overlooked in programming is that other developers have to see your code. This oversight often creates headaches when others have to see your code.

I am a consultant, and one of my specialties is rescuing projects that are overdue, overbudget, and otherwise destined to fail. The common element I see in such projects is poor coding. Among the elements I see that contribute to this, the use of sequences has to be the single biggest hindrance to productivity.

Your perspective on the matter may not afford you the luxury of seeing what others have seen. But I guarantee that once you have, you will understand how bad sequences can truly be.

I hope this is helpful.
0 Kudos
Message 16 of 22
(1,520 Views)
I would like to take a moment to applaud this post for being as inspiring as any self help book.

On a multi-megabyte diagram, I can't imagine the amount of "Insane object..." errors that must have poped up.
0 Kudos
Message 17 of 22
(1,520 Views)
"Labviewguru" wrote in message
news:50650000000500000069870000-1023576873000@exchange.ni.com...
> I stopped using sequences when I was developing what turned out to be
> a dynamic and scalable application, that I didn't know was dynamic and
> scaleable at the time. It was a 2-3mb program (one diagram! - must be
> a record...no, wait, I worked on one that was 6!) in and of itself.
> It had about 200 outer frames, with several inner embedded sequences
> of up to 70 frames each.

You went too far. Sequences are fine if you keep them simple. I ordinarily
have a sequence frame to initialize some stuff, another that has the code
that does stuff, and then one more to fix up the outputs. Not hard to
read. I can see if you make many frame sequences or sequences in sequences
(horrors) that it would be bad. But a short sequence can be easier to read
than converting to subvis since you can see the code by changing frame as
opposed to opening subvi and then going to diagram. A one step process as
opposed to two. Now if the code truly is reusable that would add weight to
the subvi argument. But most often subvi's are not reusable. They are
specific to the current application.

> I had several dozen local variables (after I
> figured out what hell using sequence locals was) and was a complete
> waste of my time, and disk space. I rethought the entire project
> (this was my first big LabVIEW program, started 4 weeks after learning
> LabVIEW) and reprogrammed it. Instead of a single 2Mb program, I
> ended up with a hierarchy of about 20 or so subVIs (a lot of the code
> in the sequences was reusable) that only took about 250k!!!! This new
> version was much easier to read, to write, to understand, to modify,
> to scale, and just plain neater.
>
> One thing you must take into consideration about writing your code.
> It really doesn't matter how easily YOU can read the code. What
> matters is how easily someone else can. The general consensus is that
> sequences are a pain in the butt. However; if noone is ever going to
> look at your code, then be my guest. But, one thing to consider: will
> you be able to understand your code a year later, two years later,
> etc.

Agreed 100%. Code gets passed on and future users will be cursing you if
your code is too complex. Simpler beats elegant every time.

>
> If you think of a sequence frame, as it should be, as a function, then
> creating a function solely on a diagram is a bad idea. Sure, its a
> bit more work to create a subVI, or a series of subVIs instead of a
> sequence (and then put the related subVIs into a higher subVI as a
> single subVI on the main diagram, in place of the sequence structure).
> But the rewards are incredible. You have reusable code. You have
> flexible code. You have a central repository for this code. Your
> code is scaleable. You have automated documentation for your code.
>
> There is no blanket policy that says that sequences are bad,
> otherwise, they wouldn't exist (although I have requested NI to remove
> multiple frame capabilities of sequence structures). But the general
> consensus is that sequences hide code, and make reading the code a big
> pain in the butt. What is often overlooked in programming is that
> other developers have to see your code. This oversight often creates
> headaches when others have to see your code.
>
> I am a consultant, and one of my specialties is rescuing projects that
> are overdue, overbudget, and otherwise destined to fail. The common
> element I see in such projects is poor coding. Among the elements I
> see that contribute to this, the use of sequences has to be the single
> biggest hindrance to productivity.
>
> Your perspective on the matter may not afford you the luxury of seeing
> what others have seen. But I guarantee that once you have, you will
> understand how bad sequences can truly be.
>
> I hope this is helpful.
0 Kudos
Message 18 of 22
(1,520 Views)
>You went too far.  Sequences are fine if you keep them simple.

I don't think that multiple frame sequences have any place on released software diagrams. I will not relent on my opinion. Multi-frame sequences serve only to confuse most people who read code.

Even when I write code for myself, just for prototyping or even fun, I stopped using multi-frame sequences.

What I do instead, is this, and you can try it, and will probably like it: String together, in a line, multiple sequence frames (single frame, connected by data wires.) This keeps the code in a single frame series, and makes the code more readable.

Just a note. In my book, I describe multiple frame sequences as being the exact equivalent of placing
subVIs on on top of the other. It really is. You are hiding code, plain and simple.

The most important thing to remember when creating code in LabVIEW is that it is a graphical language. You have the capability to create self documenting code when you make a LabVIEW program. Using multiple frame sequences defeats this, as you hide code.

Of course, everyone is entitled to their opinion. I am merely trying to point out what I discovered about their use.
0 Kudos
Message 19 of 22
(1,520 Views)
"Labviewguru" wrote in message
news:5065000000050000007E870000-1023576873000@exchange.ni.com...
>You went too far. Sequences are fine if you keep them simple.


I don't think that multiple frame sequences have any place on released
software diagrams. I will not relent on my opinion. Multi-frame
sequences serve only to confuse most people who read code.

Even when I write code for myself, just for prototyping or even fun, I
stopped using multi-frame sequences.

What I do instead, is this, and you can try it, and will probably like
it: String together, in a line, multiple sequence frames (single
frame, connected by data wires.) This keeps the code in a single
frame series, and makes the cod
e more readable.


Funny, my newreader didnt > your text. Oh well.
I do use single frame sequences like that. But if there is so much code
that you go past the edge of the screen you hide code in a way that is much
worse than using a sequence. Especially if you force the user to scroll
horizontally *and* vertically. Code should be kept to an area where a
reasonably sized monitor is able to view it all.


Just a note. In my book, I describe multiple frame sequences as being
the exact equivalent of placing subVIs on on top of the other. It
really is. You are hiding code, plain and simple.

The most important thing to remember when creating code in LabVIEW is
that it is a graphical language. You have the capability to create
self documenting code when you make a LabVIEW program. Using multiple
frame sequences defeats this, as you hide code.

Of course, everyone is entitled to their opinion. I am merely trying
to point out what I discovered about
their use.
0 Kudos
Message 20 of 22
(1,520 Views)