I was working on a Simulink model recently and was using Goto
and From
blocks to keep a very busy system from becoming a twisted mess of wires. I was informed that I was not to use Goto
and From
blocks as they are considered bad style (at least, according to my employer).
While I hold that wires should be kept connected whenever possible, I believe that Goto
and From
blocks can significantly improve the readability of a system/subsystem if the model would result in lots of crossed wires otherwise; especially if the blocks can be color-coded (e.g. purple Goto
block goes to all the purple From
blocks).
I'd supply an image of the subsystem I'm working with, but I'm not sure I can put it on here. The subsystem itself has about 12 subsystem blocks (and possibly more later) within it, each with two bus-type outputs. The first output of each subsystem goes to a Bus Creator
block, and the second output of each goes to a second Bus Creator
block. Since the subsystem are aligned vertically and the Bus Creator
s are to the right, this results in many crossed wires. I was using Goto
and From
blocks to clean up the system.
I can supply an image of a smaller, but similar model that I put together for this question.
For a system with on the order of 12 subsystems, this becomes very busy. I was using Goto
and From
blocks to connect the subsystems and the Bus Creator
s without a plethora of crossed wires.
I believe my employer may be carrying the stigma of using goto
statements from text-based languages and applying it to Goto
/From
blocks in Simulink. Generally speaking, is using Goto
and From
blocks in this way (or any way) considered to be bad style?
Description. The Goto block passes its input to its corresponding From blocks. The input can be a real- or complex-valued signal or vector of any data type. From and Goto blocks allow you to pass a signal from one block to another without actually connecting them.
Description. The Goto Tag Visibility block defines the accessibility of Goto block tags that have scoped visibility. The value you specify for the Goto tag block parameter is accessible by From blocks in the same subsystem that contains the Goto Tag Visibility block and in subsystems below it in the model hierarchy.
Blocks that represent equations and modeling components. Blocks are the main elements you use to build models in Simulink®. Use the Library Browser to browse and search the block libraries. When you find the block you want to use, add it to your model.
The Scope block displays inputs signals with respect to simulation time. A Subsystem block represents a subsystem of the system that contains it. The Subsystem block can represent a virtual subsystem or a nonvirtual subsystem. The Sum block performs addition or subtraction on its inputs.
In the Simulink Editor, selecting the From block highlights the corresponding Goto and Goto Tag Visibility blocks. When a corresponding Goto or Goto Tag Visibility block is not in the current diagram, the Subsystem block that contains the block is highlighted.
Simulink ® generates an error if you run or update a diagram that has a Goto Tag Visibility block at a higher level in the block diagram than the corresponding scoped Goto block in the masked subsystem. Use local tags when the Goto and From blocks using the same tag name reside in the same subsystem.
Bookmark this question. Show activity on this post. I was working on a Simulink model recently and was using Goto and From blocks to keep a very busy system from becoming a twisted mess of wires. I was informed that I was not to use Goto and From blocks as they are considered bad style (at least, according to my employer).
Simulink ® generates an error if you run or update a diagram that has a Goto Tag Visibility block at a lower level in the block diagram than the corresponding scoped Goto block in the masked subsystem. In the Simulink Editor, select the Goto Tag Visibility block to highlight the corresponding Goto and From blocks.
The Mathworks Automotive Advisory Board has published some modeling guidelines (PDF) that include usage of Goto
/From
. The rules they list are:
Do not have subsystems that are floating, i.e. all inputs / output ports are connected via Goto
s. One of the great things about Simulink is the ability to determine signal flow with only a cursory visual inspection, do not destroy this by linking everything with Goto
s. At least have one feed-forward and one feedback loop between subsystems connected by signal lines.
The second guideline is about the scope of the Goto
tag; keep the visibility local
as much as possible.
scoped
is acceptable also as long as you're not using the matching From
more than a couple of levels downstream from the Goto
. I've yet to come across a legitimate need for a global Goto
tag. So, all Goto
usage isn't bad, and you're right that it can improve readability in some cases. That being said, I don't think Gotos are justified for the picture above. I realize it is just an example, but I should point out that if the buses being created are virtual that order of the inputs at the creator doesn't matter, and rearranging Bus Create and Mux block inputs can work wonders for readability.
The problem with the guidelines above are that there's room for bending them, and developers on your team might do just that. Even if everyone is diligent about following them at first, you may run afoul of these guidelines one day, a long time from now, when you redraw that section of the model for refining / adding functionality. Rearranging inputs and outputs can be especially irritating in middle of implementing some cool new feature. That may be the reason your employer chose to impose a blanket ban. It is inconvenient in some cases, but is easier to enforce.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With