Ramifications of using Public vs. Function Group Output Scope

Barnhart Crane 3 years ago in IQANdesign updated by Noah Breece 3 years ago 4

I typically set the scope of a channel to public if they're used in 2 or more additional function groups, and function group output if the channel is used in only 1 other function group.

But I decided this somewhat arbitrarily. What are the ramifications of using public vs FGO? Does public scope cause things to run slower? Are there some good rules of thumb?

Public, protected and function group output, are all used in the same way. The only difference between them is how visible you want the channel to be. The rule of thumb would be to make any channel's visibility as narrow as possible, keeping your application logic structured and easy to read and maintain.

Public, protected or function group output does not produce any penalty speed-wise. Function group inputs however will add a minimal amount of CPU utilization, since it adds a separate channel that needs to be evaluated. So, using a lot of function group inputs may have an effect on your performance. On the other hand, function group inputs gives you the possibility to define a strict interface between function groups, with the help of input type and limits.

I would say it's a design choice of the application developer. It depends on how you want to structure your application logic. Using to much public/protected scope may create logic that is harder to diagnose or maintain. It will also increase the number of choices on selection menus of other channel properties that allow channels.

It would be interesting to hear other user's opinions on this topic.

My opinion is the keep public variables very limited.

If public variables are used through out the program they can induce critical races in the software. Some parts of the program are using the last cycle value and some parts using the current cycle value of the public variables. And that can be dangerous.

Thanks for the responses. Would it be true to say that paying careful attention to calculation order on the top level could eliminate the phenomenon you're talking about, Jonas? 

I have some channels appearing early on in the calculation sequence that get used in a lot of channels afterwards. It seems to me like using a public scope is appropriate so that I don't create so many unnecessary FGIs but I wanted to make sure it wouldn't cause other problems. 


Jonas what you bring up is certainly important.

If the execution order is "wrong" the line from the public scope channel will be marked red. So then you know you are using the value from the last cycle. See example below.

The digital channel Test A is executed before the public scope channel and is using the value of the public scope channel from last cycle.

The digital channel Test C is executed after the public scope and uses the value from the current cycle (grey line).

However, when there is a long sequence of channels it might be difficult to follow the execution through the entire program.


To avoid any execution order related problems you will want to reduce the number of red lines in your program to minimum and only keep those that are necessary.