Robustness of Functional Global pattern at large scales?
#1
Posted 25 December 2011 - 07:14 PM
I'm wondering though if the FG pattern is indeed as robust as it appears, especially for large-scale applications. Are there any known issues with the FG pattern (eg. memory leaks, lost data, crashes, etc) when used with large amounts of data stored in the USRs or operated for long periods of time?
My concern about the robustness of FGs is based on my impression that, although it works well, the pattern seems like an unintended use for a while or for loop (ie running the loop once just to read the current value of previously set USRs).
Thanks in advance for your thoughts and comments.
John Bergmans
#2
Posted 26 December 2011 - 10:19 PM
I'm glad that you are questioning this methodology.
First I would strongly recommend that you review this well written Field Architect blog about this very topic.
There are many many skilled LV developers that have either based their entire architecture on this tactic or used it as a staple of their programs.
These are actively running programs, and I would say there is no doubt as to the validity of this approach.
However! There are many drawbacks and caveats and I truly believe that this practice of coding represents a style which in the future we'll look back like we look back at finger paintings from grade school (cute, simplistic and far from a desirable design)
Personally speaking, I was bitten VERY recently when another developer used LV2 style globals and never took into consideration the idea of needing two of the same thing.
What ended up happening when another of the same thing was needed, was that a developer just copied 'all VI' and appended a '2' to the end of the file names so that he could have 2 of the same thing. If chills didn't just run down your spine....you may want to think about that implication in a very large application.
I'll avoid putting all my comments from the blog into this reply, but long story short, there are emerging ideas/techniques/frameworks that will help you accomplish your large application with a much more Scaleable, Modular, Reuseable, Extensible and Simple (SMoRES) .
If you have the chance to start a design from scratch and don't need to inherit someone else's choices, I would highly recommend taking this chance to implement a LV2-Global free design and move to LV 2011 instead of '2'
#3
Posted 27 December 2011 - 12:29 AM
#4
Posted 27 December 2011 - 01:37 AM
1. They solve the read/write race condition problem.
2. They can have error terminals for sequencing.
3. They can be self initialising.
4. They are singletons (unless you set the VI to clone).
A couple of comments about the blog mentioned.
I think the author missed the point about race conditions and FGs or at least didn't explain why they aren't a magic bullet to variable races.
He states "
The “read, increment, write”, then, is a critical section".
And in the original example using global variables it is intended to be. But the feature that protects the variable by using a FG is that it is placed inside a sub-vi, not that it is a FG. The exact same protection could be obtained by selecting the globals and increment then selecting "Create Subvi" and putting that in the loops.However. In all examples it is impossible to determine consistently what the output of Running total 1 or 2 would be since that would be dependent on the order which Labview executes the loops which may change with different compiles or even different execution speeds of the loops. So in reality, by using an FG we no longer have a race between the read and write operations, but we still cannot predict (reliably) the indicator values (Although we can say that they will always increase). We now have a race condition between the loops themselves.
The thing to bear in mind about FGs are that they are a programming solution to the global variable read/write race condition only and therefore an improvement over the in-built globals.
Many, however, would argue that global variables are evil whether a FG or not. But they are simple to understand, easy to debug and, marginally more complex than the in-built global. You can also put error terminals on them to sequence rather than cluttering up your diagram with frames.
That said. It is quite rare to find a FG as an exact replacement for a normal global. People tend to add more functionality (read, write, initialise, add, remove etc) effectively making them "Action Engines".
Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!
#5
Posted 27 December 2011 - 02:09 AM
#6
Posted 27 December 2011 - 04:06 AM
It's not only Action Engines that suffer from God syndrome or, indeed, scope. It's like the argument between private and protectedI'd prefer that functional globals (actually any USR) died a slow death. It is probably because I see people abuse them so easily (access scope, callers are more difficult to track than other by ref mechanisms.) As far as AEs, if I have to look at another octo-deca-pus I might just lose it.
Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!
#7
Posted 27 December 2011 - 04:05 PM
#8
Posted 27 December 2011 - 05:13 PM
FWIW it seems to me that it's not FGVs that are being talked about in that light; rather, it's the misuse of them based on misunderstanding how, when and why to consider using them.
I agree with that comment because it does seem like overkill and over reliance on text-based descriptions rather than making use of the easy to read, multi-language accessibility of the native LV symbols. I mean what is one supposed to do: put simultaneous translations into Spanish, French, German, Hebrew, Russian, Chinese (old style and new style)....along with the presumed English language standard? Isn't LV intended to be international? Aren't the primitives much more language independent?
It's not a burden to learn to navigate easily through non-text but clear diagrams. That's one of the many reasons that we use graphic representations of output data instead of just long text-based descriptions of those datasets.
#9
Posted 27 December 2011 - 07:45 PM
I'm wondering if you can say at least a little bit more about this comment and the general idea that FGVs "...always end up..." as god instantiations, and I gather you mean some form of pantheism or polytheism.
This is specific to AEs:
the "typical" usage of an action engine is to use it as a SINGLETON and that the AE itself IS the API used (have fun scoping that without another abstraction layer.) Using it as a CBR node call destroys any ease of maintainability associated with AEs (typdefing the connector pane, re assigning etc.) the only alternative at this point is to make the input/output a variant to get around the octopus connector that results, performing to/from variant. I think if you are good enough to do that, you might as well just step up to classes and type-protect your inputs/outputs, and reap all the run time performance benefit of dispatching instead of case-to-variant steps.
I think singletons are inherently not extensible and lead to "god functions." Using a by-ref pattern using SEQs or DVRs is a better way to go. If you really want to go completely nuts with software engineering and maintainability, use the actor framework or some other messaging system.
FGs: I don't even consider them useful. Once again, they are a singleton; The only time I'd be happy with them is as a top level application object for immutable objects (config data?)
Maybe this is because I'm always making something work with one unit, then down the road I end up testing 6 at a time, and all the FGs are completely useless.
#10
Posted 27 December 2011 - 10:22 PM
Try writing a logging function without a singleton.
This is specific to AEs:
the "typical" usage of an action engine is to use it as a SINGLETON and that the AE itself IS the API used (have fun scoping that without another abstraction layer.) Using it as a CBR node call destroys any ease of maintainability associated with AEs (typdefing the connector pane, re assigning etc.) the only alternative at this point is to make the input/output a variant to get around the octopus connector that results, performing to/from variant. I think if you are good enough to do that, you might as well just step up to classes and type-protect your inputs/outputs, and reap all the run time performance benefit of dispatching instead of case-to-variant steps.
I think singletons are inherently not extensible and lead to "god functions." Using a by-ref pattern using SEQs or DVRs is a better way to go. If you really want to go completely nuts with software engineering and maintainability, use the actor framework or some other messaging system.
FGs: I don't even consider them useful. Once again, they are a singleton; The only time I'd be happy with them is as a top level application object for immutable objects (config data?)
Maybe this is because I'm always making something work with one unit, then down the road I end up testing 6 at a time, and all the FGs are completely useless.
I will pull you up on a couple of points, if I may.
1. API? Possibly. That's the developers decision. Not the fault of Action Engines.
2. Typical usage as a singleton. (I'm going to throw a controversy into the mix here
They are not typically used as an equivalent (in OOP terms) of a Singleton, just that by default they are. They are typically used as the equivalent of an object (with minor limitations). The enumerations are the "Methods" and the storage is the equivalent of the Private Data Cluster. The terminals are the properties and if you want it not to be a singleton, then just select "Clone" from the properties (although I've found limited use for this).
If a designer stuffs so many "Methods" into an action engine, that is a partitioning issue, not a problem with Action Engines per se. It is the same as adding all properties and methods to one God Object.
Of course all the "Object Happy" peeps will cry about inheritance and run-time polymorphism. But like I said. Minor limitations (as far as LabVIEW is concerned-due to the constraints).
3. Variants as inputs.
I hate variants. There. I've said it
The elegant approach instead of using variants (IMHO) is to use wrap the AE in a polymorphic VI to simplify the connector pane for the end user and enable it to "Adapt To Type". Then the user doesn't need to know the data type and cast. It also exposes the "Methods" as select-able drop-downs so for purists, there is no leakage of the type-def.
In summary.....
I don't think any of the points you make are attributable to the Action Engine philosophy, more of your experience with those designers that use it. All the arguments can equally be applied to by-val Objects and from the statement "Using a by-ref pattern" I'm thinking (rightly or wrongly) that the issue is with the dataflow paradigm rather than AEs.
I'm doing to change my signature back to the old one...lol
Edited by ShaunR, 27 December 2011 - 10:30 PM.
Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!
#11
Posted 27 December 2011 - 11:25 PM
I would also add that essentially what you're saying is: byref is inherently "better" than byval and this is one situation that you have put forward to illustrate that point.
I disagree on the priority given by many to byref esp in the LV environment and that for a number of reasons. The most important is that by val is the native "core" of LVOOP and there are a number of reasons for that are best explained, if I remember correctly, in a series of notes by AQ and perhaps the white paper as well -- for those who are interested in pursuing that.
Having used FGVs for now almost 12 years, I find them a very robust way to implement, as ShaunR indicates, objects and not so much singletons, although that has become the default case for many. For years that was just about the only way to do that or anything like it that in LV. And, yes "god functions" are a problem, uh perhaps I should say, however they are instantiated. Being a class doesn't guarantee lack of god elevation.
If on the other hand you want to "cast" FGVs as CBR substitutes then, yes, you'll create some interesting entanglements. But doesn't that get back to the issue (at least potentially) of prioritization of byref constructs?
So as is the case with many LV constructs, if you don't like them, then don't use them. Just bear in mind that it isn't accurate to say that they are inherently dangerous or especially prone to idol worship.....
#12
Posted 28 December 2011 - 03:06 AM
I'd prefer that functional globals (actually any USR) died a slow death.
Try writing a logging function without a singleton.
I have built applications in the past made up entirely of AE's - which I am sure a lot of people did too before they had any OOP options available in LabVIEW - and I am sure they got it to work.
IMHO being able to use the latest techniques is an assumption - are you coding LabVIEW RT on a brick running <=8.6? - I guarantee I will be using an architecture made up of AEs if you want some form of encapsulation.
Nowdays I personally prefer LVOOP based implementations but on a module-to-module basis however, I think everything has it's place and it's up to the developer to decide what is appropriate for what use case.
So as the OP is about robustness I just wanted to post different ways of achieving the implementation of (what I consider) a robust AE.
the "typical" usage of an action engine is to use it as a SINGLETON and that the AE itself IS the API used (have fun scoping that without another abstraction layer.)... ...the only alternative at this point is to make the input/output a variant to get around the octopus connector that results, performing to/from variant.
Personally, I have never like the use of variants as the inputs and outputs to a AE as it means the developer has to know what data to supply to what method without any edit time checks. Additionally I do not like using the AE as the API as it means coupling the enum on the BD of the calling VIs - I like using wrappers around the methods (which is a call to the AE with an Enum constant). And then like ShaunR - a polyVI for the API.
Therefore in order to add robustness to the AE I found myself creating a lot of wrapper code. This was worth it IMHO as the code was less coupled, more readable, easier to make changes etc... but the extra work was a PITA and I didn't have any other options at the time.
AE/FGV/MFVI/VIG -or whatever you call it (This is how I used to do it)
This example is just a template so there is not much meat to it.
I use the term private below but I never enforced it literally e.g. with a LabVIEW Project Library - it was just a coding convention.
Also an end-user knows exactly what inputs to use for the method they are calling as and inputs can be marked required, recommended, or optional as needed:
I believe this solution is more elegant - it does require LV2009 as it uses DVR's but there is a lot less code.
LV2009 Singleton (This is how I saw AQ do it)
This uses a Class in this example - but it doesn't have to be (I just prefer it).
#13
Posted 28 December 2011 - 04:01 AM
I don't think you are comparing like-with-like there.but there is a lot less code.
The "lot less code" piccy would equate to a single frame in the AE (or as I usually do, a case statement before the main frames) and would look identical to the class version except it would have the cluster instead of the class blob (without the for loop of course).
I also suspect that your first piccy is equivalent to a shed-load of VIs.
The only difference (in reality) between a class and an AE is that an AE uses case frames to select the operation and a class uses
Everything else that is different is just anal computer science.
Edited by ShaunR, 28 December 2011 - 04:13 AM.
Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!
#14
Posted 28 December 2011 - 04:57 AM
I believe I am, because I am comparing robustness which means creating the AE with wrapper VIs for the Methods.I don't think you are comparing like-with-like there.
Yes and no - that image is equivalent to both a AE frame and it's Method Wrapper - as it has the same level of robustness (IMHO), but contains a lot less boilerplate code.The "lot less code" piccy would equate to a single frame in the AE (or as I usually do, a case statement before the main frames) and would look identical to the class version except it would have the cluster instead of the class blob (without the for loop of course).
The only difference (in reality) between a class and an AE is that an AE uses case frames to select the operation and a class uses
voodooVIs . An AE will be 1 VI with a load of frames and a typedef to select, whereas a class will be a load of VIs with more VIs to read/write the info and selection will be what object you put on the wire. (Just because you have a wizard to generate them doesn't mean less code). In this respect by wrapping the AE in a poly, you are merely replicating the accessor behaviour (figuratively speaking-in reality you are filtering) of a class and (should) incur the same amount of code writing as writing class accessors. But you will end up with 1 VI with n accessors (for an AE) rather than m VIs with n accessors (for a class).
I think you are getting hung up on the fact it has a Class in it?
Like I said this could be e.g. a cluster, the benefits/how-the-framework-works in based solely on the DVR and the IPE (as opposed to a Class).
FWIW here are my stats comparing the two (either one could have a polyVI so that is ignored):
In this example I have the exact same API, where each has the exact same number of Methods (n).
AE/MFVI with n Methods
- 1 x Main VI
- n x Methods VIs
- 1 x Enum TypeDef
- 2n x Method Cluster TypeDefs
- 3 x (Input, Output, Local/State) Cluster TypeDefs
- 1 x Main VI (FGV)
- n x Method VIs
- 1 x State Class/Cluster TypeDef
Of course all this is all based on my definition of AE robustness - like I said in previous post, you could use an AE with the enum exposed and have either:
- A variant interface
- A cluster interface - CP never changes but you have to do the bundling on the caller's BD
- Or no standard interface - where you could run out of CP inputs/outputs
And yes, if you coded the module using 1 of these 3 approaches then the stats would be different.Of course, you don't HAVE to have the accessors for an AE, it's just icing on the cake
But IMHO I don't think either approach is that robust - so to me it was never icing on the cake, it was how I implemented a Module (AE).
#15
Posted 28 December 2011 - 06:15 AM
Nope. Still not with you here....I<snip>
An action engine "by default" is a singleton, however, you are using a class cluster which is not. So if your action engine is identical to your 2009 version then the cluster at the heart of it is the same........but you don't have to use a DVR to make an AE a singleton, because it already is.
Now. To make it usable for other developers you still need to expose the different parts of the internal clustersaurus (which Is what all the type-defs are presumably for in the AE and what the poly is for so that you don't have one huge in/out cluster) but in the second example you also have to de-reference the DVR too. So are you saying that in the 2009 version you de-reference and expose one huge cluster to the external software (1 x State Class/Cluster TypeDef), or lots of VIs to de-reference and output the cluster parts (class accessors)?
What I'm not getting is that you want to break the singleton feature of an action engine (by using a class cluster?) then re-code it back again (by using a DVR) and somehow that means less typedefs for identical functioning code
What am I missing here?
Edited by ShaunR, 28 December 2011 - 06:19 AM.
Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!
#16
Posted 28 December 2011 - 07:26 AM
The class is the state data of the module (in this example!).An action engine "by default" is a singleton, however, you are using a class cluster which is not.
This state data is stored in the shift register (in both the AE and the LV2009 Singleton)
But as I mentioned before it does not have to be a class - it could be a cluster.
No different to the state data of the AE could be a class or a cluster.
But it has nothing to do with how the DVR-IPE works - so it can be ignored.
Yes, an AE is a singleton.....but you don't have to use a DVR to make an AE a singleton, because it already is.
But no, I prefer using the DVR because it is less work.
No, the clusters are all private data of the module - no clusters are exposed to the end user....you still need to expose the different parts of the internal clustersaurus (which Is what all the type-defs are presumably for in the AE and what the poly is for so that you don't have one huge in/out cluster)
The reason for having an (input/output) cluster per method (where needed) is so that each method's data is separate from another method.
I.e. you cannot accidentally bundle the wrong data at edit time into another method.
Then in the AE (main VI) you can unbundle that methods data easily.
The input to the AE (main VI) is a super-cluster of the input clusters (and the output to the AE is a super-cluster of the method output clusters) - so the CP of the AE does not ever need to change - it's interface is maintained.
The polyVI is just so you can drop one VI (the polyVI) and select which method you want.
I like to do that when creating APIs.
Both the AE and LV2009 Singleton could do this (that is why I ignored it from the stats).
No, that would violate encapsulation.So are you saying that in the 2009 version you de-reference and expose one huge cluster to the external software (1 x State Class/Cluster TypeDef),
No, they are not class accessors - it is DVR based.or lots of VIs to de-reference and output the cluster parts (class accessors)?
But yes, each method is a VI.
Accessing elements from the state data is the same as for the AE (you use unbundle).
If the state data is too complex to manage then it should be broken down e.g. into classes or clusters or whatever - but this doesn't differ between the two implementations.
No I am saying that if I want to create a robust AE I prefer to use the LV2009 Singleton method (or whatever you want to call it).What I'm not getting is that you want to break the singleton feature of an action engine (by using a class cluster?) then re-code it back again (by using a DVR)
To an end user, both will have the exact same API, but for the developer there is less code.
Using the DVR with the IPE means that the singleton feature is not broken then rebuilt - it's simply implemented a different way from the get-go.
#17
Posted 28 December 2011 - 08:52 AM
Hmmm. It seems you have picked a rather "special" action engine to demonstrate. I'd even go so far as to saying it's not one at all. Perhaps if you could put it in context with something simple (I like simple) and I'm more familiar with (e.g a list) I might be able to see the benefit.<snip>
A list will have things like Add, Remove, Insert, Get Value etc. At it's heart will be an array of something. It will basically wrap the array functions so that you have the operations exposed from a single VI. There are two inputs (a value to do the operation on and an index if required for the operation) and one output.
With this AE, how is the DVR method more robust, simpler, less coding et al?
Here she is.
Edited by ShaunR, 28 December 2011 - 08:54 AM.
Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!
#18
Posted 28 December 2011 - 12:05 PM
Why? In terms of the module (as a whole) it's core is an AE, with the those AE methods wrapped.Hmmm. It seems you have picked a rather "special" action engine to demonstrate. I'd even go so far as to saying it's not one at all.
So to me it's an AE/FGV/MFVI/VIG etc...
Perhaps if you could put it in context with something simple (I like simple) and I'm more familiar with (e.g a list) I might be able to see the benefit. A list will have things like Add, Remove, Insert, Get Value etc. At it's heart will be an array of something. It will basically wrap the array functions so that you have the operations exposed from a single VI. There are two inputs (a value to do the operation on and an index if required for the operation) and one output.
With this AE, how is the DVR method more robust, simpler, less coding et al?
As mentioned above I do not think this implementation is robust (I am assuming the the Enum is not a type def for ease of posting).
The first thing that come to mind from looking at it is that when I go to select a method I do not know which data I should set without opening the block diagram and looking at the code.
This is a simple example, but what happens when the code is more complex?
What if there 2-3 inputs are needed for each method and there was 5 methods?
What if some inputs are required and some are optional - how do you specify that?
It's going to get harder to figure out what is going on for the end user.
Once you run out of room for inputs/ouputs then you will need to use clusters - exposing this data (clusters, enum) leads to higher coupling.
Therefore by wrapping the AE I can provide a more robust API for the end user.
And if I was to go this route I would prefer to implement it with the DVR-IPE as it's less coding for me.
Don't get me wrong, writing AE as you have is valid, lightweight and works - I just think it can be more robust.
Here is an example - unlike yours, it just some BS functions, but it demonstrates the framework:
Each module has the exact same API - and that API is robust IHMO.
The DVR-IPE is more lightweight it terms of number of files and coding.
I am not saying this is the only way to make an AE more robust and I always like seeing different implementations.
If you check out LabVIEW For Everyone 3rd Ed pg 910-912 they show a similar implementation but the main points about encapsulation are the same:
- Each method bundles/unbundles has it's own input and output cluster respectively and
- The enum command is wrapped by the method
Robust AE.zip 171.98K
53 downloadsCode is in LabVIEW 2009
#19
Posted 28 December 2011 - 09:15 PM
Hmmm. It seems you have picked a rather "special" action engine to demonstrate. I'd even go so far as to saying it's not one at all. Perhaps if you could put it in context with something simple (I like simple) and I'm more familiar with (e.g a list) I might be able to see the benefit. A list will have things like Add, Remove, Insert, Get Value etc. At it's heart will be an array of something. It will basically wrap the array functions so that you have the operations exposed from a single VI. There are two inputs (a value to do the operation on and an index if required for the operation) and one output. With this AE, how is the DVR method more robust, simpler, less coding et al? Here she is.
I am with Shaun here. What magic ingredient are we missing that allows the DVR method to not have to have individual wrapper VIs for all "actions"?
Edit: should have refreshed my browser, looking at your new example now
Jon,
I still don't think your examples are the same. Surely for consistency your Singleton methods should have typedef inputs as well? If you do this you get a very similar number of files for both architectures.
Edited by neil, 28 December 2011 - 09:12 PM.
#20
Posted 29 December 2011 - 12:50 AM
I am with Shaun here. What magic ingredient are we missing that allows the DVR method to not have to have individual wrapper VIs for all "actions"?
Edit: should have refreshed my browser, looking at your new example now
Jon,
I still don't think your examples are the same. Surely for consistency your Singleton methods should have typedef inputs as well? If you do this you get a very similar number of files for both architectures.
No, the LV2009 Singleton methods do not need typedef inputs.
In the AE each method should access it's own data - it unbundles it's own inputs and in bundles up it's own outputs. The cluster helps enforce this which leads to more robust code. Additionally it standardises the API (i.e. CP) to the AE main VI.
In the LV2009 Singleton example I don't need to worry about any of that as each method is a VI so it only uses those inputs/outputs.
That is why I consider the examples the same.












