Coding philosophy : Is using global goto like using a global variable?
Show older comments
Hi,
Must I considere that using a global goto block in a Simulink model is like defining a global variable in a code?
I dont' talk about the functionnal point of view, but about "coding philosophy".
In several companies I've worked for, I've come across coding rules that recommand to use global variables as less as possible, and more often totally avoid them...
In a code, global variables are shared between functions, while in Simulink, global gotos are shared between subsystems... But subsystems are not "functions"...
So I'm wonder about this "global" Goto option in Simulink... Is it just an "option name" or is there something underlying behind this name?
GL.
Accepted Answer
More Answers (1)
Pat Gipper
on 10 Feb 2021
1 vote
The thing about global visibility is that this signal can be accessible anywhere in the entire model, from sub-system to sub-system, from the top level of the model on down. The signal name cannot be re-used anywhere else in the entire model. This makes it difficult to combine subsystems from multiple designers because of potential signal name duplication.
It is therefore encouraged that you use "local" option to the maximum extent. But local signals are only accessible in From blocks at the same diagram level as the Goto block. This is painful restriction results in the "scoped" option, which allows you to have the From block at lower levels within the same sub-system. But the one drawback is that you are forced to also include a "Goto Tag Visibility" block at the top subsystem where the signal is going to be used.
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!